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 :
Finance | Project Operations, Human Resources, ...
Answered

X++ Code to populate rec id field in one table using rec id field of another table?

(0) ShareShare
ReportReport
Posted on by

I have table1 and table 2 and they have the relation as follows:

          table2.RefRecIdfield == table1.RecId

I need to populate the RecId field using X++ Code. Can someone suggest the code?

I have the same question (0)
  • Martin Dráb Profile Picture
    236,025 Most Valuable Professional on at
    RE: X++ Code to populate rec id field in one table using rec id field of another table?

    I see you've created a follow-up thread: How do i use the "InsertEntityToDataSource" method on parent table to populate the RefRecid of Child table using RecId of Parent table.

    Does it mean that we're done in this thread? Didn't you forget to mark verify the answer?

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: X++ Code to populate rec id field in one table using rec id field of another table?

    My first reply really tells you the solution. If you need more detailed help, please share more details about your requirement. But if you already shared the actual requirement, then your initial question already contains the solution, just remove one '=' symbol and your code is ready. Well you need also a semicolon (;) in the end of the line.

  • Smoors Profile Picture
    on at
    RE: X++ Code to populate rec id field in one table using rec id field of another table?

    Sorry, my bad i think the otherwise but yeah i need to populate the RefRecId of table2 with RecId of table1.

    Can you please suggest me the X++ code for the same?

  • Verified answer
    Martin Dráb Profile Picture
    236,025 Most Valuable Professional on at
    RE: X++ Code to populate rec id field in one table using rec id field of another table?

    Your relation shows something else that you say you need.

    You should populate RefRecIdField if Table2 with RecId of Table1.

    Your request to populate Table1.RecId field from Table2.RecId makes no sense. You can't assign RecId, you don't want the same RecId in both tables and the request completely ignores RefRecIdField.

    Create a record in Table1 - the system will populate RecId on insert. Then use this value in Table2.RefRecIdField.

  • Smoors Profile Picture
    on at
    RE: X++ Code to populate rec id field in one table using rec id field of another table?

    " table2.RefRecIdfield == table1.RecId" this is the relation between the 2 tables. I need to populate the RecId field of table1 from RecId field of table2 , can you please suggest the code for that?

  • nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: X++ Code to populate rec id field in one table using rec id field of another table?

    Hi,

    just remove one of the"=" symbols from your code and you're there.

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 846 Super User 2025 Season 2

#2
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 838

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 818 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans