Cancelling the delivery note through batch job

Hi Everyone,

I have to cancel the delivery note through batch job in AX 2012.

I have used the below piece of code in my batch job class.

menuFunction = new MenuFunction(menuitemActionStr(SalesFormLetter_PackingSlipCancel), MenuItemType::Action); args.record(custPackingSlipJourloc);
menuFunction.run(args);

But i am getting the below stack trace error.

"Stack trace: Invalid attempt to call SalesFormLetter.main running in CIL on the client."

Please help me to solve this issue.

Regards,

Madhan

The technical reason is that SalesFormLetter.main() is a client-bound method and can’t be used in CIL. It’s also logically wrong - calling the menu item would merely open Packing slip posting form, which is not very useful in batch. You don’t want to use either main() nor any dialog.

Hi Martin,

Thanks for the quick reply.

Is there any other way to cancel the delivery note through batch job? Can you please help me on this.

Regards,

Madhan

Of course that it’s possible to write it correctly.

If you want to start the process from batch, you have to fill parameters in code, because the batch wouldn’t be capable to fill them in a dialog form. When everything is set up, call the run() method. You can also simplify it a little bit with update(). Like this:

SalesFormLetter formLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip);
formLetter.parmVersioningUpdateType(VersioningUpdateType::Cancel);
formLetter.update(salesTable);

Specifying right parameters is up to you.