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

I have the same question (0)
  • Crispin John Augustine Profile Picture
    37,081 on at

    Hi,

    Try a manual field assignment for the mandatory fields (instead of using data()) and check if it is importing.

  • Ashein Profile Picture
    275 on at

    I have checked, and then it works. But i am trying to do it without manual field assignment. Because of all the fields that exist in InventTable

  • Verified answer
    André Arnaud de Calavon Profile Picture
    301,109 Super User 2025 Season 2 on at

    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

  • Crispin John Augustine Profile Picture
    37,081 on at

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

    The system understands based on fieldIds.

  • Ashein Profile Picture
    275 on at

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

  • Ashein Profile Picture
    275 on at

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

  • André Arnaud de Calavon Profile Picture
    301,109 Super User 2025 Season 2 on at

    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.

  • Crispin John Augustine Profile Picture
    37,081 on at

    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.

  • Ashein Profile Picture
    275 on at

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

  • Brian Kinser Profile Picture
    815 on at

    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);
        }
    }

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 AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans