Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Answered

Copying table records to duplicate table (date() / buf2buf)

(0) ShareShare
ReportReport
Posted on by 275

Hi everyone

I am trying to copy records from inventTable to my duplicateInventTable. But when i try, my duplicate table ends up being filled up with empty records.

I have tried to use buf2buf but when i create/duplicate inventTable it ends allocating new fieldId's so i can't use it.

And when i use data(), it just fills my duplicate table with empty records.

Please help.

4212.1.png

7026.2.png

*This post is locked for comments

  • Suggested answer
    kehlet Profile Picture
    462 on at
    RE: Copying table records to duplicate table (date() / buf2buf)

    Can you explain what the purpose is? If you truly want a copy of the table, then you could just insert it in a SQL statement and adjust the SYSTEMSEQUENCES table for the DuplicateInventTable afterwards.

    An alternative is to do an insert_recordset or a RecordInsertList with insertDatabase() at the end, which would be a bit slower, but allow for more granular control of the data to be inserted.

    But, if you could give the purpose of this, it would be easier to help, unless the above helps.

  • NNikolov Profile Picture
    5 on at
    RE: Copying table records to duplicate table (date() / buf2buf)

    The buf2BufByName() should possibly check not only on name but also on type.

  • Brian Kinser Profile Picture
    815 on at
    RE: Copying table records to duplicate table (date() / buf2buf)

    a little late but.....would buf2buf by name work? I have used this successfully in the past for archiving and logging....basically just like buf2buf but use field names instead

    static void buf2BufByName(Common  _from, Common  _to)
    {
        DictTable   dictTableFrom   = new DictTable(_from.TableId);
        DictTable   dictTableTo     = new DictTable(_to.TableId);
        DictField   dictFieldFrom;
        FieldId     fieldIdFrom     = dictTableFrom.fieldNext(0);
        FieldId     fieldIdTo
        ;


        while (fieldIdFrom && ! isSysId(fieldIdFrom))
        {
            dictFieldFrom   = new DictField(_from.TableId, fieldIdFrom);


            if(dictFieldFrom)
            {
                fieldIdTo = dictTableTo.fieldName2Id(dictFieldFrom.name());


                if(fieldIdTo)
                    _to.(fieldIdTo) = _from.(fieldIdFrom);
            }


            fieldIdFrom = dictTableFrom.fieldNext(fieldIdFrom);
        }
    }

  • Ashein Profile Picture
    275 on at
    RE: Copying table records to duplicate table (date() / buf2buf)

    Ok, thanks. I just thougth there were and easier way to do it.

  • Crispin John Augustine Profile Picture
    37,081 on at
    RE: Copying table records to duplicate table (date() / buf2buf)

    No, comparing fieldIds will only complicate things. I just wanted to point out that only manual assignment works with your code.

    Andre's suggestion to use a Map is your best available standard AX option.

  • André Arnaud de Calavon Profile Picture
    294,715 Super User 2025 Season 1 on at
    RE: Copying table records to duplicate table (date() / buf2buf)

    Hi Ashein,

    The map is an AOT object where you define the mapping once. Yes, you have to manually map it. You can write an own routine to search field ID's based on field names, but that would also be quite cumbersome.

  • Ashein Profile Picture
    275 on at
    RE: Copying table records to duplicate table (date() / buf2buf)

    Crispin, so i should compare each fieldId from both tables?

  • Ashein Profile Picture
    275 on at
    RE: Copying table records to duplicate table (date() / buf2buf)

    But if i use maps, then i would have to manually map every field to each table?

  • Crispin John Augustine Profile Picture
    37,081 on at
    RE: Copying table records to duplicate table (date() / buf2buf)

    I get what you think. (based on same field name)

    The system understands based on fieldIds.

  • Verified answer
    André Arnaud de Calavon Profile Picture
    294,715 Super User 2025 Season 1 on at
    RE: Copying table records to duplicate table (date() / buf2buf)

    Hi Ashein,

    The buf2buf() and data() methods are intended to be used on the same table. You can try to use a table Map object where you can link fields of various tables.

    More information can be found here: msdn.microsoft.com/.../bb278211.aspx

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics AX (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 100 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 48

#3
shanawaz davood basha Profile Picture

shanawaz davood basha 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans