ARGS is your friend in the world of AX. It allows you to pass records, the calling locations (form, report, query etc) , enums and the list goes on! I use it often to pass the objects, records, etc that I need to have in scope when I access an object from another object. Its very easy to use and requires very little effort on your part to get the desired results.
Simple declaration of args
Args args = new Args();
Very simple and easy right
Now lets try passing args an record.
select firstonly custTable where custTable.AccountNum == ‘XXXX’
if(custTable)
{
args.record(custTable);
}
Now lets view a snippet of code that passes in a record and runs a report using the record passed in. I create an instance of the report run class I pass in the calling object which is the object that is calling the report. I pass in the current record that is being passed to the report. I create a new Args instance to hold all of this information. I pass in the name of the report. I instantiate the report run object and call the init and and run methods of the report.
Next I override the init method of the report and put a condition that checks to see if a record was passed to the report from the args object. If so I do not allow the user to be interactive with the report and I sent the report straight to the screen. I set a report variable eHeader to the record that was passed to the report. If there is no calling record to the report meaning the report is being launched from a menu or elsewhere besides a place with a calling record then I allow interaction of the report query for the users to select the range criteria they want to use.
Then I override the fetch method and I keep the super in place to allow the standard query to run however before the super I use a condition to determine if a record has been passed into the report. If so I set a query of a key field to the a field from the record I passed in.
You can use args to do the same with forms as well
You can pass in objects such as maps to run reports I have done this as well and I find it very helpful and useful
void printPickList(wfsEMPickListHeader wfsEMPickListHeader)
{
Args args = new args();
ReportRun reportRun;
;
args.name(reportStr(wfsEMExportPickList));
args.caller(this);
args.record(wfsEMPickListHeader);
reportRun = classfactory.reportRunClass(args);
reportRun.init();
reportRun.run();
}
public void init()
{
super();
if(element.args().record())
{
this.report().interactive(false);
this.query().interactive(false);
this.printJobSettings().preferredTarget(PrintMedium::Screen);
eHeader = element.args().record();
}
else
{
this.report().interactive(true);
this.query().interactive(true);
}
}
public boolean fetch()
{
boolean ret;
if(element.args().record())
{
element.query().dataSourceTable(tablenum(wfsEMPickListHeader)).
addRange(fieldnum(wfsEMPickListHeader,PickListId)).value(eHeader.PickListId);
}
ret = super();
return ret;
}
void wfsRMRunManualTruckLoadIdForm()
{
wfsWhseUser wfsWhseUser;
FormRun formRun;
Args args = new Args();
boolean ret = false;
;
args.record(this);
formRun = new MenuFunction(menuitemdisplaystr(wfsManualTruckLoadSelection),
MenuItemType::Display).create(args);
formRun.run();
formRun.wait();
}

Sorry, the comment form is closed at this time.