Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Suggested answer

Custom PO field to select item pointer

Posted on by 25
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.
 
Categories:
  • Suggested answer
    Mohana Yadav Profile Picture
    Mohana Yadav 59,139 Super User 2024 Season 2 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
    IH-07071528-0 25 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
    IH-07071528-0 25 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
    Mohana Yadav 59,139 Super User 2024 Season 2 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans