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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Compile X++ in runtime.

(0) ShareShare
ReportReport
Posted on by

Hello,

I need that a user write a code (admin user) as a user, and compile it in X++ code, verify it, and may run it (by some circumstances).

I have seen once that option integrated in some forms in X++ - Don't remember where.

BTW - How can I compile code in X++ code (and run it)?

Can I limit the code to specific syntax code (that even it will be compiled in X++ - It won't compile, or be compiled on specific circumstances in runtime)?

Thanks :)

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    You can use runBuf() and evalBuf() function to execute X++ code at runtime. It's obviously very dangerous, so you should be extremely careful. Your other option would be actually to save a TreeNode and compile it. And you might do some research to see if you can't utilize XLNT for your purpose.

    Regarding your specific syntax, you would have to write your own parser. It may be easier to embed a scripting language and build your DSL there, rather than trying to do everything in X++.

  • Suggested answer
    Rachit Profile Picture
    4,015 User Group Leader on at

    Hi Eitan,

    In addition to Martin, one example I can mention is that in AX 2009 there was ability to define X++ code in Export/Import Definiation Group >> Table Setup >> Import criteria. Sample shown below:

    7142.1.jpg

  • Srinath Sundaresan Profile Picture
    510 on at

    You can compile a treenode. For example below is the code to compile all forms.

    Mark this question as answered if it helps.

    static void myJobAOTcompile(Args _args)

    {

       treeNode treeNode;

       treeNode = TreeNode::findNode(#FormsPath);

       treeNode.AOTcompile();

    }

  • Community Member Profile Picture
    on at

    Martin Drab is right - this is dangerous.

    So, I need as much to protect what can be written in code.

    Nevertheless, I don't give that ability to everyone.

    What Rachit Garg explained is a good solution I need (I add X++ within a method), so I control what user can write or not (in some manners).

    How can I do that (partial X++ within a method)?

    How in AX 2009 that could be handled (partial code)?

    Also - In AX 2009 - Does the code is added to AOT object?

    Thanks :)

  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    You can't compile and execute a half of a method, but you obviously can add the header and footer of the method to what you get from users. It's exactly what happens in Rachit's example, if you specify a filter expression for AOT search etc.

    And the explanation how to run is still the same as above.

  • Suggested answer
    Srinath Sundaresan Profile Picture
    510 on at

    You can use the XPPCompiler class to do compilation. I wrote a simple job to explain how this works. You can also read a xpp file and compile it using this API.

    The XPPCompiler class has compile method. I think the same is used in the form Rachit mentioned above.

    static void Job9(Args _args)

    {

       XppCompiler x=new XppCompiler();

       x.compile(@"static void Job10(Args _args)

           {

               str s;

               s= 1.0;

           }");

       error (x.errorText());

    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans