Hi Nitesh,
Thanks for responding, it was a problem with parent rec id not flowing correctly to invoice lines and hence causing the failure to determine parent rec id at source document level.
It's working now as expected.
Here is a quick dirty job for what I am doing
static void FreeTextInvoice(Args _args)
{
CustInvoiceTable custInvoiceTable;
CustInvoiceLine custInvoiceLine;
CustTable custTable;
CustPostInvoice custPostInvoice;
LineNum lineNum;
int i;
container acctPattern;
;
acctPattern = [strFmt("%1-Disp","main ac no"),"main ac no",1,"CostCentre","cost centre value"];
ttsbegin;
custTable = CustTable::find("cust id");
custInvoiceTable.initFromCustTable(custTable);
custInvoiceTable.insert();
ttscommit;
for(i=1; i<=3; i++)
{
ttsbegin;
custInvoiceLine.clear();
custInvoiceLine.initValue();
custInvoiceLine.initFromCustInvoiceTable(custInvoiceTable);
custInvoiceLine.AmountCur = 10.00;
custInvoiceLine.Description = "FreeTxIv" + int2str(i);
custInvoiceLine.TaxItemGroup = "GST";
custInvoiceLine.ParentRecId = custInvoiceTable.RecId;
custInvoiceLine.LedgerDimension = AxdDimensionUtil::getLedgerAccountId(acctPattern);
if(!lineNum)
{
lineNum = CustInvoiceLine::lastLineNum_W(custInvoiceLine.ParentRecId);
}
lineNum += 1;
custInvoiceLine.LineNum = lineNum;
custInvoiceLine.insert();
ttscommit;
}
custPostInvoice = new CustPostInvoice(custInvoiceTable);
custPostInvoice.run();
}