Skip to main content

How to pass value from form to class, AX 2012

Courtesy : DUG

Dynamics User Group



It's very simple to pass value from a form to a class by defining a method on form and using args.caller() in the class.

1. Take a String control in the form design like  string Customer Name.
2. Go to String control properties and set "Auto declaration" property to "Yes".
3. Go to form methods -> new method -> write return type method like;
    
     public str customerName()
     {
           return CustomerName.Text();
     }

4. Go to main() method of the class and type following:

    public static void main(Args args)
    {
           str custName;
           ;
   
           if(formHasMethod(args.caller(), identifierStr(customerName)))
           {
                custName =  args.caller().customerName();
           }
   
           info(strFmt("%1", custName));
    }

5. Open form enter some text into text box and call this class through menuItem button. It will display the entered text in the info log.

6. Likewise, write code for each and every control.

Comments

Popular posts from this blog

Creating BOM journal using code AX 2012

courtesy: http://www.andesoft.net/creating-bom-journal-using-x-code-ax-2009-ax-2012/ https://community.dynamics.com/ax/f/33/t/96262.aspx http://learnax.blogspot.com/2010/01/x-code-to-create-and-post-inventory.html static void createBomJournal_working(Args _args) {     InventJournalTable      journalTable;     InventJournalTrans      journalTrans;     InventJournalTableData  journalTableData;     InventJournalTransData  journalTransData;     InventTable             inventTable;     InventDim               inventDim;     Counter                 cnt;     InventJournalCheckPost  journalCheckPost = new InventJournalCheckPost();     InventTransId           inventTransId, inventTransIdFather;     InventBat...

Run SSRS report using x++ code | AX 2012

This post describes how to run an SSRS report through x++ code and passing report parameters as well. Its a simple code and comments are added for further ease in code understanding! public static void runSSRSReport() {     SrsReportRunController controller;             controller = new SrsReportRunController();     controller.parmLoadFromSysLastValue(false);      // write report name and its design in quotes that you want to run     controller.parmReportName("ReportName.DesignName");      // set additional, optional properties like setting landscape to true     controller.parmReportContract().parmPrintSettings().landscape(true);          // set print destination screen/printer/file etc.     controller.parmReportContract().parmPrintSettings().printMediumType (SRSPrintMediumType::S...

Auto create job card journal in Production | AX 2012

Multiple journals are created in the production process. When the order is started route card journal and picking list journal are auto created. But system does not create job card journal automatically. It requires a small customization. Following method can be called when the production order is started with the production order id passed as the parameter. /// <summary> /// This method auto creates Job Card Journal and its lines against selected production order. /// </summary> private void autoCreateJobCardJournal(ProdId _prodId) {     ProdJournalTable    prodJournalTable;     ProdRoute           prodRoute;     ProdRouteJob        prodRouteJob;     ProdJournalRoute    prodJournalRoute;     ProdParametersDim   prodParametersDim;     int   ...