passing parameters from a form to a batch job class

I have a form with a grid, where multi-selection is enabled. I need to pass those selected records to a class, which runs a batch job.
The form is CustOpenInvoiceListpage. On the invoice tab, you can PrintRange of the invoices, as email , using dialog box for setting the range, through SMTP, in a batch.
Or, you can print selected records from a grid, using print selected button, via Outlook, from the client.

I need to send selected invoices as email attachments, but in batch - via SMTP.

I have utilized MultiSelectionHelper to get the selected records IDs into the string, on a click method of a button that i have created.
Here is the code:

helper = MultiSelectionHelper::construct();
helper.parmDatasource(custTransOpen_ds);
custTransOpenLocal = helper.getFirst();

args = new Args();

while (custTransOpenLocal.RecId != 0)
{
//<pn 7nov18 insert record manipulation here - concatenating recID, or any other data to PACK - or trying container
//selectedInvoices = selectedInvoices + "," + int2str(custTransOpenLocal.RecId);


select Invoice from custTransSelected
where custTransSelected.RecId == custTransOpenLocal.RefRecId &&
custTransSelected.AccountNum == custTransOpenLocal.AccountNum;

con = conIns(con, 1, custTransSelected.Invoice);

custTransOpenLocal = helper.getNext();

}

//args.parm(selectedInvoices);
args.parm(con2Str(con, ','));


//<pn 7nov18 passing string to batchJob class

menuFunction = new MenuFunction(menuitemActionStr(ESC_EmailSelectedInvoicesJob), MenuItemType::Action);
if(menuFunction && menuFunction.checkAccessRights())
{
menuFunction.run(args);
}
I pass that string using Args.parm to a main() method of class that runs in a batch - sending Invoices. The string is retrieved successfully.
Here:

public static void main(Args _args)
{
str selectedCustTransInvoices;

container con2;
int i;

ESC_CustInvoiceEmailJob custInvoiceEmailJobRunBase = ESC_CustInvoiceEmailJob::newCustInvoicesToEmail(_args.parmEnum(), _args.parm());



//-- <pn 7nov18 try with container

selectedCustTransInvoices = _args.parm();

con2 = str2con(selectedCustTransInvoices, ',', true);


//<pn 2nov18 run without a dialog?

if (custInvoiceEmailJobRunBase.prompt())
{
custInvoiceEmailJobRunBase.run();
}

Here is the problem:
Since the processing and email sending is run on the server, class has to be packed , with some   values from the dialog form, which gets called from the class. This is where i loose a string that i had in Main() of the form. RunBase.run() can not have any arguments.

so here is the macro to pack in class declaration:
#LOCALMACRO.CurrentList
accountType,
fromAccount,
toAccount,
invoiceDateType,
fromTransDate,
toTransDate,
printCopyOriginal,
printerSettingsCopy,
printerSettingsOriginal,
usePrintManagementDest,
custInvoicesToPrint,
selectedCustTransInvoices

#ENDMACRO

But by the time the instance is packed, there is nothing in the selectedCustTransInvoices variable...

if i would be able to keep that value and unpack it when the batch job is started on the server, there would be no need for a dialog form.
So, my question is, how do i keep the value of a string of Invoice IDs, to use it to build a query for printing selected invoices?

Thanks,

Related
Recommended