Sunday, 22 March 2015

pass value from form to class in AX 2012

here we want to pass the value from the form to class.



if (args.caller() && formHasMethod(args.caller(), identifierstr(M)))
 {
        formRunObject = args.caller();
        formRunObject.M();    
}

this code does not work in ax 2012 but it works fine in ax 2009.

 here  we have to create a class , a menu item as action   and then call this menu item in form's click method and then pass the value in the class through menu item and  catch the vaulue in the main method of class.

First create a form  demo form with a table called demo table where we will have only one field over there   and one grid in design and one button over there.



then create a class1


create a menu item with action type and assign the class to that.



then write the click method of that button as 

void clicked()
{
    //super();

    MenuFunction    mf;
    args            args = new Args();
    ;


    args.record(DemoTable);


    mf = new menufunction(identifierstr(MenuItem1), MenuItemType::Action);
    mf.run(args);
}

now open the form and insert a record and click the button you will get output as 


1 comment:

  1. Good post, thanks for sharing your knowledge with us. By the way, I just saw microsoft dynamics 365 pricing and I'm quite shocked the prices are so low. I thought it's going to cost much more for my fairly large accounting company, but it looks like the opposite.

    ReplyDelete

intercompany PO multiple product receipt by x++

public void processStampICPO(PackingSlipId _deliveryNote,                             Transdate _deliverydate,                             ...