Skip to main content

Notifications

Announcements

No record found.

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

Copy existing field to a customfield (same table) with if condition

(0) ShareShare
ReportReport
Posted on by 130

Hi All,

We have modified a page in BC with a new field. I have a Description3 and Description. 

I would like - if Description <> '' and Description3 = '' then Description3 = Description

Currently I am doing this on a Trigger OnOpenPage - but I recognize that this is problematic if many users are accessing the same page :S. Does adding a setfilter make this better? Please see below

    trigger OnOpenPage()
    begin
        rec.SetFilter("Document Type", '%1', rec."Document Type"::Order);
        rec.SetFilter("Document No.", rec."Document No.");

        repeat
            if (rec.multiLineDescription = '') and (rec.Description <> '') then begin
                rec.multiLineDescription := rec.Description;
                rec.modify();
            end;
        until rec.next = 0;
    end;

Thank you in advance!

  • SammySevens Profile Picture
    SammySevens 130 on at
    RE: Copy existing field to a customfield (same table) with if condition

    Thank you Zhu, I understand the use of actions now - this is definitely the way to go to perform one time processes.

    I added an action on the purchaseLines page and ran it once. That performed the task in full - and then i removed the trigger OnOpenPage - which wasn't a good idea to begin with.

    The reasoning for using the description3 is because my stakeholders were complaining that the original description field was single line and when users wrote something too long, it would be hard for them to read.

    So I created multilinedescription - which I called description 3. It was a significant effort, but I think it is ok for now.

    Thank you again

  • Verified answer
    YUN ZHU Profile Picture
    YUN ZHU 74,115 Super User 2024 Season 2 on at
    RE: Copy existing field to a customfield (same table) with if condition

    Hi, First of all, I think your development is a bit risky. It seems that you don’t use the standard Description and recreated a new Description3. When Description3 is empty, it is equal to Description, but when Description is empty and Description3 is not empty, you don’t do any process?
    In the BC, such as Sales Order Line, Item Journal and other table will use Item Description. If you don’t consider it, the Description of these page may be empty.

    In addition

    For action:

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-page-ext-object

    pastedimage1674004446176v1.png

    For OnValidate (Field) Trigger

    https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/triggers-auto/field/devenv-onvalidate-field-trigger

    Hope this helps.

    Thanks.

    ZHU

  • SammySevens Profile Picture
    SammySevens 130 on at
    RE: Copy existing field to a customfield (same table) with if condition

    Hi Zhu,

    I'm not familiar with actions, and one caveat is that I want to back-fill historical data with values from Description to Description3, but moving forward Description will be invisible, and Description3 will be used instead (I have this part working).

    So moving forward Description3 may <> Description. Could you link me to a good example of using actions and onValidate? Would it go on the page?

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 74,115 Super User 2024 Season 2 on at
    RE: Copy existing field to a customfield (same table) with if condition

    Hi, If this is a newly added field (Description3 ) and historical data already exists, it is recommended that you add a new Action to do this processing. Because it's a one-time thing.

    If you are in a new environment and don't have any data yet, I suggest adding the processing to the OnValidate Trigger of the Description, and there is no need for a loop.

    Hope this helps.

    Thanks.

    ZHU

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans