web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Custom PO field to select item pointer

(1) ShareShare
ReportReport
Posted on by 35
Hi,
I'm very new to AL so bear with me.
I've inserted a field in 'Purchase order subform'.
 
 
pageextension 50110 "Field on PO Line" extends "Purchase Order Subform"
{
    layout
    {
        addafter("No.")
        {
            field("Web Model Code"; Rec."Web Model Code")
            {
                ApplicationArea = all;
            }
        }
    }
}


 
tableextension 50110 "New Web product list field" extends "Purchase Line"
{
    fields
    {
        field(50105; "Web Model Code"; Code[50])
        {
            Caption = 'Web Model';
            DataClassification = ToBeClassified;
        }
    }
}
I need a ability to update this field by 'cut and paste' with a web part number (code[50] and when entered to do a lookup to see if there's a match in another custom field on the Item table. (This will very much speed up item entry in our case.)
If so it will select that item on the purchase line. If not it will clear.
Doing this as our web based item codes are over 20 chars. (Limit for Item No.)
 
I just need the general method, I'm sure I can work out the rest given enough research! I sort of anticipate using an OnChange or similar event to set the 'No.' field and then hopefully the fill the purchase line.
Any advice appreciated.
 
I have the same question (0)
  • Suggested answer
    Mohana Yadav Profile Picture
    61,005 Super User 2025 Season 2 on at
    Use OnValidate trigger of the "Web Model Code" table field.
    You can apply the filter on Item record using Setrange
    if Item record found then validate the Purchase Line's No. field.
    If not found then just assign a blank value to the Web Model Code 
  • IH-07071528-0 Profile Picture
    35 on at
    Hello,
    Yes the suggestion worked well and when I input into "Web Model Code" it correctly selects the correct item number and all item details but if I select an item normally by the "No." dropdown 'Web Model Code' is not filled with Item."Web Model" despite my Onlookup trigger.
    I guess I'm doing it wrong? How do I go about auto filling "Web Model Code" on a normal item select?
     
    pageextension 50110 "Field on PO Line" extends "Purchase Order Subform"
    {
        layout
        {
            addafter("No.")
            {
                field("Web Model Code"; Rec."Web Model Code")
                {
                    ApplicationArea = all;
     
                }
            }
        }
    }


     
    tableextension 50110 "New Web product list field" extends "Purchase Line"
    {
        fields
        {
            field(50110; "Web Model Code"; Code[50])
            {
                Caption = 'Web Model';
                DataClassification = ToBeClassified;
     
                trigger OnLookup()
                var
                    Item: Record Item;
                begin
                    "Web Model Code" := Item."Web Model";
                end;
     
                trigger OnValidate()
                var
                    Item: Record Item;
                begin
                    if "Web Model Code" <> '' then begin
                        Item.SetRange("Web Model", "Web Model Code");
                        if Item.FindFirst() then begin
                            Validate("No.", Item."No.");
                            "Web Model Code" := Item."Web Model";
                            // Other stuff in here
                        end else
                            "Web Model Code" := ''; // Clear the field if no item is found
                    end;
                end;


     
            }


     
        }
     
    }
  • Suggested answer
    IH-07071528-0 Profile Picture
    35 on at
    OK I am being slow.
    The way AL works with the Record object confuses me still but now fixed. It only updates the field on a lookup rather that when the product is selected via the 'No.' field but it will do for now until my knowledge increases.
     
                trigger OnLookup()
                var
                    Item: Record Item;
                begin
                    Item.SetRange("No.", "No.");
                    if Item.FindFirst() then begin
                        "Web Model Code" := Item."Web Model";
                    end;
     
                end;
  • Suggested answer
    Mohana Yadav Profile Picture
    61,005 Super User 2025 Season 2 on at
    you have to validate the field in Onlookup trigger instead of just assigning which will trigger OnValidate trigger.
     
    Rec.Validate("Web Model Code", Item."Web Model");

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,092

#2
YUN ZHU Profile Picture

YUN ZHU 663 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 515

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans