web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Unanswered

How to modify all table fields (record to record)

(0) ShareShare
ReportReport
Posted on by 5

Hello everyone

I am writing a script that is supposed to copy Item data from one company to another.

I have a problem with Items that already exist - I want to modify them but I don't want to write all fields in the table. I decided to create loops and use RecordRef and FieldRef. Unfortunately, this approach takes a long time (over 24 hours).

sourceTable.OPEN(objectId, FALSE, fromCompany);
sourceFieldFilter := sourceTable.FIELD(54);
sourceFieldFilter.SETFILTER('FALSE');
IF sourceTable.FINDSET THEN BEGIN
  targetTable.OPEN(objectId, FALSE, toCompany);
  REPEAT
    targetTable.INIT;
    FOR intCounter := 1 TO sourceTable.FIELDCOUNT() DO BEGIN
      sourceField := sourceTable.FIELDINDEX(intCounter);
      targetField := targetTable.FIELD(sourceField.NUMBER);
      targetField.VALUE(sourceField.VALUE);
      IF FORMAT(sourceField.CLASS) <> 'FlowField' THEN BEGIN
        targetTable.MODIFY(FALSE);
        COMMIT;
      END;
    END;
  UNTIL sourceTable.NEXT = 0;
END;
targetTable.CLOSE();
sourceTable.CLOSE();


I am looking for another solution. I wrote something like that (but it doesn't work):

fromItem.INIT;
fromItem.CHANGECOMPANY(companyName);
fromItem.SETFILTER(fromItem.Blocked, 'FALSE');
IF fromItem.FINDSET THEN BEGIN
  REPEAT
    IF toItem.GET(fromItem."No.") THEN BEGIN
      toItem := fromItem
      toItem.MODIFY;
    END;
    COMMIT;
  UNTIL fromItem.NEXT = 0;
END;

System has a problem with MODIFY function, if the record already exists - as if it would also like to modify the key (??).
I get the following message:

pastedimage1576230523728v1.png

There are over 200 fields in my table and I don't want to write each field in the style:

toItem.Fields1: = fromItem.Fields1;
toItem.Fields2: = fromItem.Fields2;
toItem.Fields3: = fromItem.Fields3;
....
....
toItem.Fields200: = fromItem.Fields200;

toItem.MODIFY

it will work but I am looking for another solution.

Do you have any suggestions?

I have the same question (0)
  • Kamil Olszewski Profile Picture
    5 on at

    Problem solved

    toItem.TRANSFERFIELDS(fromItem, FALSE);

    instead of

    toItem := fromItem;

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,993 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 1,116 Super User 2026 Season 1

#3
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 557 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans