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.
 
  • Suggested answer
    Mohana Yadav Profile Picture
    60,226 Super User 2025 Season 1 on at
    Custom PO field to select item pointer
    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");
  • Suggested answer
    IH-07071528-0 Profile Picture
    35 on at
    Custom PO field to select item pointer
    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;
  • IH-07071528-0 Profile Picture
    35 on at
    Custom PO field to select item pointer
    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
    Mohana Yadav Profile Picture
    60,226 Super User 2025 Season 1 on at
    Custom PO field to select item pointer
    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 

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,430 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,043 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans