Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

Combining the values of 2 fields into one new column

Posted on by 53

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

  • 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 21,091 Super User 2024 Season 1 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;

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans