1

I have a question about adding AOT objects by X++ Code on D365 FO. The goal, is to automate creation of security duty, via x++ code, instead of doing it manually

I'm trying actually with the Following code,

public static void main (Args _args)
{
    #AOT
    str objectName  = 'MySpecTable' ;
    TreeNode    nodePath = TreeNode::findNode(#TablesPath);
    TreeNode    nodePath1;

   nodePath1 = nodePath.AOTfindChild(objectName);

    if(nodePath)
    {
        nodePath.AOTadd(objectName);
        //nodePath.AOTsave();
        info("Sec privilege well added");
    }
    else
    {
        nodePath.AOTadd(objectName);
        nodePath.AOTsave();
        info("Table well added");
    }
}

But i receive the Following error,

X++ error

is there any way to achieve this goal.to be able adding them via code.

Thanks

rjv
  • 1,058
  • 11
  • 29
Adnane
  • 21
  • 6
  • If the file is under source control, it will be read only. You will need to use elevated permissions to save to disk. Have you tried adding a codeaccesspermission object to elevate the permissions? – rjv Jul 17 '19 at 17:01
  • 4
    Have you looked at the new metadata API? http://dev.goshoom.net/en/2016/11/new-metadata-api/ – Alex Kwitny Jul 17 '19 at 18:36

1 Answers1

1

This is not possible anymore as, compared with previous AX versions, where code and metadata was dynamically interpreted in runtime, F&O executes only pre-compiled assemblies (like any other .NET application). Same way you can't create a C# class on a running .NET assembly, you can't do it either in Finance and Operations application.

Required Security artifacts must be properly created in Visual Studio, compiled and deployed to the runtime environment (UAT, PROD or whatever), and then the security configuration itself (linking these artifacts between them or with users) is now stored in the database, so it can be done directly in the Security setup forms. It can also be exported and imported with Data entities within the standard form.

What you can do is create a Visual Studio extension to automatically create such objects, so then they can be compiled and deployed correctly.

Dharman
  • 30,962
  • 25
  • 85
  • 135
j.a.estevan
  • 3,057
  • 18
  • 32