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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

filling a table object dynamically

(0) ShareShare
ReportReport
Posted on by

I created a new table Called Gen. Journal Header Hist. that I will use to fill all posted records from the table Gen. Journal Header. Both tables have exact same rows and datatypes. Is there a way to fill the History object dynamically from the Journal header table without hardcoding the fields? Can I loop through the fields of the history table dynamically and fill it using  RecordRef ?

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Nareshwar Raju Vaneshwar Profile Picture
    5,596 on at

    Hi,

    If both tables are identical, especially the Field No.s with the datatype are identical, you can use TRANSFERFIELDS in your code.

    For example, let's assume, you have to log an history record from the journal record. On the Gen. Journal Line Table (Table 81), you can right something like in OnModify() / OnInsert() trigger.

    GenJournalHistory.SETRANGE(GenJournalHistory."Entry No.", "Entry No.");

    IF GenJournalHistory.FIND('-') THEN

    BEGIN

      GenJournalHistory.TRANSFERFIELDS(Rec);

      GenJournalHistory.MODIFY(TRUE);

    END

    ELSE

    BEGIN

      GenJournalHistory.INIT;

      GenJournalHistory.TRANSFERFIELDS(Rec);

      GenJournalHistory.INSERT(TRUE);

    END;

    If you want to insert/modify block entries from Gen. Journals to Gen. History then, code would look something like,

    GenJournals.SETRANGE(GenJournals."Entry No.");

    IF GenJournals.FINDSET THEN

    BEGIN

       REPEAT

          GenJournalHistory.SETRANGE(GenJournalHistory."Entry No.", GenJournals."Entry No.")

          IF GenJournalHistory.FIND('-') THEN

          BEGIN

             GenJournalHistory.TRANSFERFIELDS(GenJournals);

             GenJournalHistory.MODIFY(TRUE);

         END

         ELSE

         BEGIN

            GenJournalHistory.INIT;

     GenJournalHistory.TRANSFERFIELDS(GenJournals);

     GenJournalHistory.INSERT(TRUE);

        END;

    UNTIL GenJournals.NEXT = 0

    END;

     

    In the second scenario, it's better if you run this code from a codeunit/report.

    Here the GenJournalHistory is the record variable of the Gen. History table.

    Hope it helps.

  • Ashwini Tripathi Profile Picture
    4,624 on at

    If both tables are identical in field number and datatype, transferfield should be the best option. You can see this is broadly used in navision codes while copy document or creating posted documents.

    Using RecRef and looping through fields will not be good choice.

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 > 🔒一 Microsoft Dynamics NAV (Archived)

#1
HoangNam Profile Picture

HoangNam 7

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans