Hi guys,
I'm spending too much time on my first parallel code in AX 2012 so I'd like to use some help.
What I need to do is to fill one table with many data using query and some calculations. (Single thread batch took more than a day and I need to optimize it)
Now I have three classes, main class which is called from menu item, class with logic and contract for parm methods.
This is my process method of the class which is called to start the batch.
[SysEntryPointAttribute]
public void process()
{
Query query = new Query(queryStr (ASCSProfitMargin)); // Query name.
QueryRun qr;
QueryBuildRange qbr;
fromDate= Datestartmth(datemthFwd(systemdateget(), -11));
toDate= systemdateget();
qbr = query.dataSourceTable( tableNum (custInvoiceTrans)).addRange( fieldNum (custInvoiceTrans, InvoiceDate));
qbr.value(SysQuery::range(fromDate, toDate));
qr = new QueryRun(query);
ttsBegin;
delete_from table;
ttsCommit;
while (qr.next())
{
mController = new SysOperationServiceController(classStr(ASCProfitMarginRunTaskService),
methodStr(ASCProfitMarginRunTaskService, process));
// Fetch the data contract from within the controller
mContract = mController.getDataContractObject('_theContract');
mContract.parmCustInvoiceTrans(qr.get(tableNum (CustInvoiceTrans)));
mContract.parmCustInvoiceTransDim(qr.get(tableNum (ASCCustInvoiceTransDim)));
// Check if we are batch processing or not
if(this.isExecutingInBatch())
{
if(!mBatchHeader)
{
mBatchHeader = BatchHeader::getCurrentBatchHeader();
}
// Create a runTimeTask within the current batch job
mBatchHeader.addRuntimeTask(mController, this.getCurrentBatchTask().RecId);
}
else
{
// Just run it immediately
mController.run();
}
}
// If we're processing in batch, then save the batch header
if(mBatchHeader)
{
mBatchHeader.save();
}
}
It's creating main batch and many small batches but they inserting empty lines.
That's the method of threads logic:
public void process(ASCProfitMarginDataContract _theContract)
{
try
{
ttsBegin;
fromDateDialog = Datestartmth(datemthFwd(systemdateget(), -2));
// fromDateDialog = Datestartmth(datemthFwd(systemdateget(), -11));
toDateDialog = systemdateget();
// monthCount = 12;
monthCount = 3;
custInvoiceTrans = _theContract.parmCustInvoiceTrans();
custInvoiceTransDim = _theContract.parmCustInvoiceTransDim();
<--- there's my calculation logic --->
tableProfitMargin.insert();
ttsCommit;
}
catch (Exception::Deadlock)
{
retry;
}
}
The problem is that it's inserting many records but all of their values are null.
It looks like it didn't takes data from contract parm or something like that. Am I missing something?
That's one of parms method I use example:
[DataMemberAttribute]
public CustInvoiceTrans parmCustInvoiceTrans(CustInvoiceTrans _custInvoiceTrans = custInvoiceTransSum)
{
;
custInvoiceTransSum = _custInvoiceTrans;
return custInvoiceTransSum;
}