Code to generate code in dynamics ax

Source: Internet
Author: User
Code
Code to generate code in dynamics ax Good morning, the following job will create a new static method on the salesline table
Runtime. Use it as a tutorial for treenodes 'aotadd (), aotsetsource (),
Aotcompile () and aotfindchild () methods. Note that access to such code shocould be restricted through security keys,
Namely the 'sysdevelopment' key since this code definitely uses a dangerous
Api. Public static void createmethodtest (ARGs _ ARGs)
{
# AOT

# Define. mynewstaticmethod ('mystaticmethod ')

# Define. Methods ('Methods ')
 
Treenode parentnode;

Treenode methodnode;
Memberfunction submethodnode;

Sysdicttable = new sysdicttable (tablenum (salesline ));

Source source = "public static void
Mynewstaticmethod ()/n"
+ "{/N"
+
";/N"
+"
Info (/"test/");/N"
+ "}/N ";
;
 
If
(Hassecuritykeyaccess (
Securitykeynum (sysdevelopment ),
Accesstype: delete ))
{
Parentnode =
Treenode: findnode (# tablespath + '//' + sysdicttable. Name (); If (parentnode)
{
Methodnode =
Parentnode. aotfindchild (# methods); submethodnode =
Methodnode. aotfindchild (# mynewstaticmethod );
If
(! Submethodnode)
{
Submethodnode =
Methodnode. aotadd (# mynewstaticmethod );
}

Submethodnode. aotsetsource (source, true); // true sets 'state' parentnode. aotcompile ();
}
}
} Et voila! Right after execution, you will have a new static method in
AOT under data dictionary/Tables/salesline/methods/: public static void mynewstaticmethod (){
;
Info ("test ");
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.