Let's say I activate the vendor invoice workflow and I open a new vendor invoice, I complete it and then I submit it. After submitting the invoice, I would like to automatically close the invoice and pop a new one, which I could complete, submit and another invoice would open, and so on... So far, I have been able to close the invoice after submitting and I have tried to use the MenuFunction to open a new invoice, but it seems that I can't open it because it is not "detached" from the parent (the first vendor invoice which I just submitted)
So I have tried this code :
MenuFunction menuFunction;
menuFunction = new MenuFunction(menuitemActionStr(PurchFormLetter_NewInvoiceAction), MenuItemType::Action);
menuFunction.run();
When I use it in a job, it works just fine, but when I use it after closing the first invoice, it never opens, and the first invoice does not close. I have placed this code in Class\VendInvoiceHeaderWorkflow\main at the end of the method like this :
if ( _args.caller().name() == formStr(VendEditInvoice))
{
_args.caller().close();
menuFunction = new MenuFunction(menuitemActionStr (PurchFormLetter_NewInvoiceAction), MenuItemType::Action);
menuFunction.run();
}
And this is why I was wondering if it would be better to use the FormRun class to open the new invoice instead of the MenuFunction. I have been working on this code :
PurchFormLetter purch;
Args args;
FormRun run;
purch = PurchFormLetter::construct(DocumentStatus::Invoice, classStr(FormletterService), methodStr(FormletterService, postPurchaseOrderInvoice), SysOperationExecutionMode::Synchronous, menuitemActionStr("VendEditInvoice"));
args = new args(formStr(VendEditInvoice));
args.caller(purch);
run = ClassFactory.formRunClass(args);
run.init();
run.run();
run.detach();