Hi
I do understand the reason for your question, as I needed to build a similar solution.
A lot of functionality in AX is initiated from a form-button, where a filter on a data-source is the key for selection in that subsequent process.
If you now want to simulate that process without the interference of a form (user) (for instance when it's a homegrown web-service process), the subsequent process still requests a form-data-source.
My solution is based on several sources, and tweaked a bit: (I need to post a wmsShipment record autonomous)
void postShipment(WMSShipment _wmsShipment)
{
Args args = new Args();
Form frm;
FormBuildDesign fbd;
FormRun fr;
FormBuildDataSource fbds;
FormDataSource fds;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
wmsShipmentOption wmsShipmentOption = new wmsShipmentOption();
;
// Construct a form
frm = new Form();
fbds = frm.addDataSource(_wmsShipment.name);
fbds.table(_wmsShipment.TableId);
fbd = frm.addDesign("Design");
args.object(frm);
// Run just some parts of the form, in order to have the form-data-source available afterwards
fr = new FormRun(args);
fr.init();
// Setting the query filter to just one record I want to pass
fds = fr.dataSource(1);
qbds = fds.query().dataSourceNo(1);
qbr = qbds.addRange(FieldName2Id(_wmsShipment.TableId, "ShipmentId"));
qbr.value(_wmsShipment.shipmentId);
fds.executeQuery();
// This can be skipped, as we actually rather not have this form show on screen
// fr.run();
// fr.detach();
// retrieve that dataSource with just that single record.
fds = fr.dataSource(1);
_wmsShipment = fds.getFirst();
// All preparations done:
// Now run the PackingSlip software
wmsShipmentOption.parmPackAllQuantitiesAndPrint(true);
args.record(_wmsShipment);
args.caller(fr);
args.parmObject(wmsShipmentOption);
new MenuFunction(menuitemactionstr(SalesFormLetter_PackingSlip), MenuItemType::Action).run(args);
// Don't forget to clean-up the form, although it hasn't been shown on screen.
fr.close();
}
Hope this helps.
Bert