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();
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(con2Str(con, ‘,’));

//<pn 7nov18 passing string to batchJob class

menuFunction = new MenuFunction(menuitemActionStr(ESC_EmailSelectedInvoicesJob), MenuItemType::Action);
if(menuFunction && menuFunction.checkAccessRights())
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.

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())

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. can not have any arguments.

so here is the macro to pack in class declaration:


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?


Please use the </> button in the rich formatting view to past source code. It preserves code indentation, which makes code much easier to read. Also, please remove unused variables and other things complicating your code without adding any value.

Your main() method can be written this way:

public static void main(Args _args)
    ESC_CustInvoiceEmailJob custInvoiceEmailJobRunBase = ESC_CustInvoiceEmailJob::newCustInvoicesToEmail(_args.parmEnum(), _args.parm());
    str selectedCustTransInvoices = _args.parm();
    container con2 = str2con(selectedCustTransInvoices, ',', true);
    if (custInvoiceEmailJobRunBase.prompt())

Notice that you fill in con2, but you never pass the value to custInvoiceEmailJobRunBase, therefore the variable has no effect at all. If you want to do that, you should have a parm method accepting the container and populating a member variable, which should be added to the CurrentList macro.

Thanks Martin, you are right, i was not using the container variable at all, since i would have to convert it to string again after i retrieve it in a class, so i didn’t see a point in passing that container as a parameter. Regardless, the string i was receiving in Main() method of the class, i wasn’t able to populate in CurrentList macro. Hence when the class was instantiated on server, there was nothing in that string variable. So i decided to use a temp table to keep selected records , then just use that table in a class to create a datasource for getting InvoiceJournal data for emailing invoices. I know it is not the most elegant solution but its working so far…