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

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!

I have the same question (0)
  • Suggested answer
    YUN ZHU Profile Picture
    95,307 Super User 2025 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

  • SammySevens Profile Picture
    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?

  • Verified answer
    YUN ZHU Profile Picture
    95,307 Super User 2025 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
    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

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 3,377

#2
Jainam M. Kothari Profile Picture

Jainam M. Kothari 2,696 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 1,512 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans