Skip to main content
Community site session details

Community site session details

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

Update custom fields on Sales Order from enum selection

(4) ShareShare
ReportReport
Posted on by 75
I have an Enum field on a Sales Order Page extension where the user will make a selection and when that selection is made, a lookup should find the corresponding record in a custom table and update fields in the Sales Order Extension with values from that record.
 
This is what I have but it does seem to like that I reference the enum field ADDRID and will be an error in future versions of BC.
 
Any suggestions?
 
Thanks!
 
 
           Group("Ship From Address")
            {
                field("ADDRID"; rec."ADDRID")
                {
                    ApplicationArea = All;
                    Caption = 'Address ID';
                    ToolTip = 'Select ADDRID';
                }
                field("Name"; rec."Name")
                {
                    ApplicationArea = All;
                    Caption = 'Name';
                    ToolTip = 'Enter Name';
                }
                field("Address"; rec."Address")
                {
                    ApplicationArea = All;
                    Caption = 'Street Address';
                    ToolTip = 'Enter Street Address';
                }
                field("City"; rec."City")
                {
                    ApplicationArea = All;
                    Caption = 'City';
                    ToolTip = 'Enter City';
                }
                field("State"; rec."State")
                {
                    ApplicationArea = All;
                    Caption = 'State';
                    ToolTip = 'Enter State';
                }
                field("Zip"; rec."Zip")
                {
                    ApplicationArea = All;
                    Caption = 'Zip Code';
                    ToolTip = 'Enter Zip Code';
                }
            }
        }
        modify("ADDRID")
        {
            AssistEdit = true;
            trigger OnAssistEdit()
            var
                AddrRec: Record FromAddresses;
                AddrList: Page "FromAddresses List";
 
            begin
                if Rec."ADDRID" = '' then begin
                    Message('ID cannot be blank.');
                    exit;
                end;
                SpecRec.SetRange("ADDRID", Rec."ADDRID");
            end;
        }        
  • Verified answer
    MJ-27012000-0 Profile Picture
    75 on at
    Update custom fields on Sales Order from enum selection
    What ended up work was not using and enum field for the drop down. Did a TableRelation on the ADDRID field in the SalesOrderTableExtension to the table that contains the address records.
     
            field(50134; "ADDRID"; Code[12])
            {
                DataClassification = ToBeClassified;
                TableRelation = FromAddresses.ADDRID;
            }
     
    for the SalesOrderExtensionPage, used the following code...
     
                    field("ADDRID"; rec."ADDRID")
                    {
                        ApplicationArea = All;
                        Caption = 'Address ID';
                        ToolTip = 'Select ADDRID';
     
                        trigger OnValidate()
                        var
                            SH_ADDR: record "Fromaddresses";
     
                        begin
                            SH_ADDR.reset();
     
                            If SH_ADDR.get(rec.ADDRID) then begin
                                rec.Name := SH_ADDR.Name;
                                rec.Address := SH_ADDR."Address";
                                rec.City := SH_ADDR."City";
                                rec.State := SH_ADDR."State";
                                rec.Zip := SH_ADDR.Zip;
                            end;
                        end;
                    }
     
    Thanks to all that assisted...
  • Suggested answer
    Sohail Ahmed Profile Picture
    4,844 on at
    Update custom fields on Sales Order from enum selection
    Just use the trigger OnValidate in the field
     
     
    ✅ Mark this answer as verified if it helps you.
  • MJ-27012000-0 Profile Picture
    75 on at
    Update custom fields on Sales Order from enum selection
    Actually I had one thing incorrect but still no luck
     
    field("ADDRID"; rec."ADDRID")
                    {
                        ApplicationArea = All;
                        Caption = 'Address ID';
                        ToolTip = 'Select ADDRID';
                        trigger OnValidate()
                        var
                            SH_ADDR: record "Sales Header";
     
                        begin
                            SH_ADDR.reset();
     
                            SH_ADDR.SetRange("ADDRID", rec."ADDRID");
     
                            If SH_ADDR.FindSet() then
                                repeat
                                    //if SH_ADDR.ADDRID = rec.ADDRID then begin
                                    SH_ADDR.Name := (rec."Name");
                                    SH_ADDR.Address := (rec."Address");
                                    SH_ADDR.City := (rec."City");
                                    SH_ADDR.State := (rec."State");
                                    SH_ADDR.Zip := (rec."Zip");
     
                                    SH_ADDR.Modify(true);
                                    CurrPage.Update();
                                //end;
                                until SH_ADDR.Next() = 0;
                        end;
     
                    }
  • Suggested answer
    Ramesh Kumar Profile Picture
    5,520 on at
    Update custom fields on Sales Order from enum selection
     
    Thanks
    Ramesh
     
    If this was helpful, please check the "Does this answer your question?" box and mark it as verified.
  • Suggested answer
    RockwithNav Profile Picture
    7,288 on at
    Update custom fields on Sales Order from enum selection
    For me your code is not getting in-lined with what you are trying to achieve. You should be writing your code on the OnValidate trigger of the enum field. Based on every selection write your code and then it will exactly behave the way you want it to.
     
  • MJ-27012000-0 Profile Picture
    75 on at
    Update custom fields on Sales Order from enum selection
    Actually I asked and got answered a similar question here...
     

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

News and Announcements

Now Available: 2025 Release Wave 2

Quick Links

Ramesh Kumar – Community Spotlight

We are honored to recognize Ramesh Kumar as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Sohail Ahmed Profile Picture

Sohail Ahmed 2,655

#2
Mansi Soni Profile Picture

Mansi Soni 1,574

#3
YUN ZHU Profile Picture

YUN ZHU 1,453 Super User 2025 Season 1

Featured topics

Product updates

Dynamics 365 release plans