Skip to main content

Notifications

Business Central forum
Answered

Combining the values of 2 fields into one new column

editSubscribe (0) ShareShare
ReportReport
Posted on by 43

Hi Guys,

I have made a new table extension and added a new field Ship to External No:

        field(50003; TBLSHP_ExternalNo; Text[30])
        {
            Caption = 'Ship-to External No.';
        }

However what i want to do now is to get the value of 2 existing fields and combine them as the value of the new table.

For example the current values of the fields are:

Thus the value of the new field "Ship To External No" must reflect "01121212-002"

How can one achieve this?

Thanks

Categories:
  • Suggested answer
    Combining the values of 2 fields into one new column
    Or you can make the source a function (which always returns the combination of the two fields)
     
    field(50003; TBLSHP_ExternalNo; GetCustNoAndCode())
     
            {
     
                Caption = 'Ship-to External No.';
     
            }
     
    local procedure GetCustNoAndCode(): Text
    begin
         exit(format(Rec."Customer No" + Rec.Code));
    end;
  • Verified answer
    Nitin Verma Profile Picture
    Nitin Verma 20,989 Super User on at
    RE: Combining the values of 2 fields into one new column

    Hi,

    You should call those events for your table in the codeunit or you can write the below code On OnInsert trigger and OnModify Trigger as well.

    [EventSubscriber(ObjectType::Table, database::"YourTable", 'OnAfterInsertEvent', '', true, true)]

       local procedure OnAfterInsertEvent_YourTable(var Rec: Record "YourTable")

       begin

           if (rec."Customer No." <> '') and (rec.code <> '') then

               rec."External Document No." := rec."Customer No." + ' ' + rec.Code;

       end;

       [EventSubscriber(ObjectType::Table, database::"YourTable", 'OnAfterModifyEvent', '', true, true)]

       local procedure OnAfterModifyEvent_YourTable(var Rec: Record "YourTable")

       begin

           if (rec."Customer No." <> '') and (rec.code <> '') then

               rec."External Document No." := rec."Customer No." + ' ' + rec.Code;

       end;

Helpful resources

Quick Links

Take the Community feedback survey!

Answer this brief 15-question survey about your Community experience…

Demystifying Copilot: Service Edition with Sundar Raghavan

Sundar answers more questions about Copilot for Service...

Dynamics 365 Business Central vs Finance and SCM

Take a look at the key differences between Business Central and…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,375 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 223,308 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,140

Featured topics

Product updates

Dynamics 365 release plans