web
You’re offline. This is a read only version of the page.
close
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 105
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;
        }        
I have the same question (0)
  • MJ-27012000-0 Profile Picture
    105 on at
    Update custom fields on Sales Order from enum selection
    Actually I asked and got answered a similar question here...
     
  • Suggested answer
    RockwithNav Profile Picture
    8,459 Super User 2025 Season 2 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.
     
  • Suggested answer
    Ramesh Kumar Profile Picture
    7,523 Super User 2025 Season 2 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.
  • MJ-27012000-0 Profile Picture
    105 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
    Sohail Ahmed Profile Picture
    11,110 Super User 2025 Season 2 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.
  • Verified answer
    MJ-27012000-0 Profile Picture
    105 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...

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,921

#2
YUN ZHU Profile Picture

YUN ZHU 2,012 Super User 2025 Season 2

#3
Jainam M. Kothari Profile Picture

Jainam M. Kothari 1,999 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans