Contact Me

Total Pageviews

Monday 4 August 2014

Pass Parameters Between a Form and a Class in Axapta

Hi, everybody!


Sometimes, we want to pass parameters between form and class, and we don't know how to do it easily. In this case, we want to pass the form datasource to the class.


First of all, we need to create a class and a menu item that calls this class. Afterwards, we put this Axapta x++ code in a clicked() method of a new button of the form:


Class name is DASEmplDuplication and Form is EmplTable.

void clicked()
{
   MenuFunction    mf;
   Args            args = new Args();
   ;


   args.record(EmplTable);


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


Meanwhile, in the main() method of the DASEmplDuplication class, we need to put this Axapta x++ code to get the datasource:


static void main(Args args)
{
    DASEmplDuplication  DASEmplDuplication;
    EmplTable           localEmplTable;
    ;


    if(args.record().TableId == tablenum(EmplTable))
        localEmplTable = args.record();

        info(strfmt("%1",localEmplTable.EmplId)); 
        //Process form's Datasource Record in Class
    ...
}

No comments:

Post a Comment