Extension Development:Page not opening in Edit mode and pre-filtered with the No. from the item list

mtlmonkmtlmonk Member Posts: 48
edited 2020-04-09 in NAV Three Tier
Hi,

Extension development

I'm coding a new action button from the Item List to call a new list form which would have 2 fields: Item No., Extra field (non relevant). Both fields form the primary key on this new page.

When opening this new page, I would expect to have it open prefiltered with the Item No. (which it does), but it doesn't prefill the "item No." field on thew new record. You manually have to key it in, which defeats the purpose of linking the Item record to it.

Here's code snippets:

New page:

Page 50100 "XYZ Item Cross References"
{
Caption = 'Cross References';
PageType = List;
SourceTable = "XYZ Item Cross Reference";


layout
{
area(content)
{
repeater(Control1000000000)
{
field("Item No."; "Item No.")
{
}
field("xyz No."; "xyz No.")
{
}
}


Item List page:
pageextension 50102 "CGI Item List" extends "Item List"
{
layout
{

}

actions
{
addafter("Submittal Cross Ref")
{
action("xyz Omnitracs Cross Ref")
{
Caption = 'xyz Cross Ref';
Image = Change;
Promoted = true;
PromotedCategory = Process;
PromotedIsBig = true;
RunObject = page "XYZ Item Cross References";
RunPageLink = "Item No." = field ("No.");
}
}
}
}

Hoping someone can help. Thanks.

Answers

  • DenSterDenSter Member Posts: 8,304
    I had the same issue with that, it just would not work the same as it used to in C/AL. I ended up programming the page to automatically set those values.

    First you need a global variable, call it 'LinkedItemNo' type Code[20]

    Then, add a trigger to catch the filtered Item No value into this variable
    trigger OnOpenPage()
        begin
            if LinkedItemNo = '' then begin
                LinkedItemNo := CopyStr(GetFilter("Item No."), 1, 20);
            end;
        end;
    

    Then, add another trigger to catch when the page creates a new record:
    trigger OnNewRecord(BelowxRec: Boolean)
        begin
            "Item No." := LinkedItemNo;
        end;
    

    I hate programming the page that way because it's supposed to work just by using the RunPageLink property. The weird thing is that the same thing does work on other pages. I could not figure out why it did not work on one but it did work on another. Anyway, this ended up working for me, hope it helps you. Let me know either way
  • DenSterDenSter Member Posts: 8,304
    By the way, if you like programming opening the page, and you like to create a variable for the page, you'll need a function to set the LinkedItem value:
    procedure SetLinkValues(NewItemNo: Code[20])
        begin
            LinkedItemNo := NewItemNo;
        end;
    
  • ESanabiaESanabia Member Posts: 3
    Hello,
    I'd prefer to use "TableRelation" property for fields using tableextension instead using pageextension.
  • mtlmonkmtlmonk Member Posts: 48
    > @DenSter said:
    > I had the same issue with that, it just would not work the same as it used to in C/AL. I ended up programming the page to automatically set those values.
    >
    > First you need a global variable, call it 'LinkedItemNo' type Code[20]
    >
    > Then, add a trigger to catch the filtered Item No value into this variabletrigger OnOpenPage()
    begin
    if LinkedItemNo = '' then begin
    LinkedItemNo := CopyStr(GetFilter("Item No."), 1, 20);
    end;
    end;
    >
    >
    > Then, add another trigger to catch when the page creates a new record:trigger OnNewRecord(BelowxRec: Boolean)
    begin
    "Item No." := LinkedItemNo;
    end;
    >
    >
    > I hate programming the page that way because it's supposed to work just by using the RunPageLink property. The weird thing is that the same thing does work on other pages. I could not figure out why it did not work on one but it did work on another. Anyway, this ended up working for me, hope it helps you. Let me know either way

    I was hoping not having to code when it's supposed to be working off the bat. No choice then. Thank you.
  • DenSterDenSter Member Posts: 8,304
    I agree, and I don't like programming this type of thing either, but if it doesn't work the way it's supposed to you can either stare at it until it goes away or do something about it.

    If you want, you can try to reproduce the issue in a standard container and submit it as an issue here: https://github.com/microsoft/AL/issues
  • ilbuuromarilbuuromar Member Posts: 1
    Incase anyone is having this similar problem i solved by making two changes

    1. add
    RunPageMode = Edit;
    
    to the action from which you are calling the other page
    2. add
    PopulateAllFields = true;
    
    to the page which you are opening as this will populate the fields using the filters

    you can read more at
    RunPageMode = https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-runpagemode-property

    PopulateAllFields = https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/properties/devenv-populateallfields-property
Sign In or Register to comment.