Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Creating and using tab...
Finance forum
Answered

Creating and using tables through code X++

Posted on by 501

Hi, 

I need to create multiple tables dynamically through X++ code. There are multiple codes available for creation of tables. But once the table is created and in the same code we want to use that table's buffer to insert record. How to use that.

Like we have created a table through X++ named "MyTable". And then in the same method or class, I want to use this table. But I can't create a table buffer for this MyTable as it will give compile time error that this table doesn't exist.

So please share how to use a table which is we are creating through X++ code.

  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 290,263 Super User 2024 Season 2 on at
    RE: Creating and using tables through code X++

    Hi Sharukh,

    The discussion continued.. To answer the question about custom fields and workflow. No this is not possible. It should be defined from the workflow document query which is actually maintained in the AOT. So, indeed the custom fields are intended to be used on forms and data entities only.

    I don't see any relation between a KPI and a workflow. Can you explain this?

  • Martin Dráb Profile Picture
    Martin Dráb 228,112 Most Valuable Professional on at
    RE: Creating and using tables through code X++

    Well, maybe "they want" isn't a sufficient business justification. Is it really impossible to identify data needed for things like annual performance review in advance and develop it in the usual way?

    Anyway, I would rather don't allow HR define data models. They're simply not trained to do such things.

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Creating and using tables through code X++

    You can't create any AOT objects in runtime of D365FO. So it's not just about tables.

    In D365FO the source code and metadata are created and modified with Visual Studio in a development system. Then, a build system builds .Net assemblies (DLL) files from the source code objects (which are xml files) to create a deployable package.

    The runtime uses these DLLs to run the application logic. The runtime can't manipulate source code or build new DLLs. 

    So, design and runtime are fully separated in D365FO, unlike in AX2012.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 228,112 Most Valuable Professional on at
    RE: Creating and using tables through code X++

    Development is done in development environments. Then all code and metadata is built to binaries (such as DLL files) and these binaries are installed to other environments, including production. You can change behavior at runtime by X++, but you can't change the binaries. That includes everything, not just tables.

    Although doing such things used to be possible, it was very dangerous and sometimes horribly abused...

  • Shahrukh Profile Picture
    Shahrukh 501 on at
    RE: Creating and using tables through code X++

    Hi Martin,

    There are multiple types of documents that we can create in the system. Like annual performance review document, termination letter, experience letter etc.

    Lets say Annual performance review form for an employee:

    HR wants to create multiple KPI/Fields. And on the bases of those KPI/Fields, they need to set up the workflows as well.

  • Shahrukh Profile Picture
    Shahrukh 501 on at
    RE: Creating and using tables through code X++

    In AX 2012, other than creating a new table, we could create fields on an existing table, create new forms, create new controls on the forms, etc. through x++. So if we can't do any of these things through code or it is only for new tables that we can't create new tables through code but we can still do other things from X++ code?

  • Martin Dráb Profile Picture
    Martin Dráb 228,112 Most Valuable Professional on at
    RE: Creating and using tables through code X++

    As already mentioned, these things are not possible anymore - you'll have to design a different technical solution, or even to rethink the design of business processes.

    What's the business case behind "User has the option to specify as many fields as he wants to show on the form"?

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Creating and using tables through code X++

    That code is for AX2012 where you can develop new AOT objects in runtime, and even develop in Prod. In d365FO all dev work is done in Visual Studio in a dev system. You can't create AOT objects with x++ anymore, only with Visual Studio.

  • Shahrukh Profile Picture
    Shahrukh 501 on at
    RE: Creating and using tables through code X++

    Hi Nikolaos,

    Thanks for your reply.

    I have seen this type of code in many blogs. This also creates a new table through code.

    Am is confusing something?

    TreeNode      treeNode;

    #AOT

    treeNode = TreeNode::findNode(#TablesPath);

    treeNode.AOTadd("Table_Test");

    SqlDataDictionary::synchronize();

  • Shahrukh Profile Picture
    Shahrukh 501 on at
    RE: Creating and using tables through code X++

    We need to dynamically add fields on the form and then use them in workflows as well. Can custom fields be used in workflows conditions? Apparently, it looks custom fields can only be used on the forms and in the entities.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,263 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,112 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans