title: How to add AOT objects by x++ code on D365 FO
body: <p>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</p>
  
  <p>I'm trying actually with the Following code, </p>
  
  <pre><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");
      }
  }
  </code></pre>
  
  <p>But i receive the Following error,</p>
  
  <p><a href="https://i.stack.imgur.com/s27xS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s27xS.png" alt="X++ error"></a></p>
  
  <p>is there any way to achieve this goal.to be able adding them via code.</p>
  
  <p>Thanks</p>