hljs.configure({cssSelector: "code"}); hljs.highlightAll();

Friday, August 7, 2020

Macros In Dynamics Ax 2012

With the macro capabilities in X++, you can define and use constants and perform conditional compilation. Macros are unstructured because they are not defined in the X++ syntax. Macros are handled before the source code is compiled. You can add macros anywhere you write source code: in methods and in class declaration

Macros are used to minimize Hard coding In select statements.

Macros Are pre-compiled.

There are two  types of Macros

*  Global  Macro

       It is Macro that comes under Aot Library Files Which Can be used All over the application.

 it is defined as follows:

       

#define.Macroname("I am a AOT Micro") // string values 


 Try This In a job

like this you wiil get an result

Ex:  Info(strfmt('%1' , #Macroname));

* Local Macro

 Local macros can be used in within in their declaration classes.

static void Job9(Args _args)

{

    CustTable custtable;

    date  fromdate =  2\5\2012;

    date ToDates =  2\6\2012;

    VendInvoiceJour vendinvoicejour;

    #localmacro.mymicro

    vendinvoicejour.invoicedate >= fromdate &&  vendinvoicejour.invoicedate <= ToDates

    #endmacro

    while  select * from vendinvoicejour where #mymicro

    info(strfmt('%1--%2-                         %3',vendinvoicejour.InvoiceDate,vendinvoicejour.InvoiceAmount,vv.InvoiceId));

Result:

}

Thank you!

1 comment: