First insert in header table like this.
custInvoiceTable.clear();
custInvoiceTable.initFromCustTable(custtable);
custInvoiceTable.insert();
Then Insert in invoice line table.
custInvoiceLine.clear();
custInvoiceLine.initValue();
//setup main account as required
offsetDimensions = ["3434","3434", 0, "", ""]; // you can set a Main Account with multiple financial dimensions
custInvoiceLine.LedgerDimension = AxdDimensionUtil::getLedgerAccountId(offsetDimensions);
custInvoiceLine.initFromCustInvoiceTable(custInvoiceTable);
custInvoiceLine.ItemId = "erw234324"; //custom field
custInvoiceLine.Quantity = custinvoicetrans.Qty;
custInvoiceLine.UnitPrice = 1210 ;
custInvoiceLine.modifiedField(fieldNum(CustInvoiceLine, UnitPrice));
custInvoiceLine.Description = custinvoicetrans.itemName();
custInvoiceLine.ParentRecId = custInvoiceTable.RecId;
if(!lineNum)
{
lineNum = CustInvoiceLine::lastLineNum_W(custInvoiceLine.ParentRecId);
}
lineNum += 1;
custInvoiceLine.LineNum = lineNum;
custInvoiceLine.InvoiceTxt = custinvoicetrans.InvoiceId+"\n"+date2StrXpp(custinvoicetrans.InvoiceDate);//change it as per need
custInvoiceLine.insert();
Post Invoice
Select custInvoiceTable1 where custInvoiceTable1.RecId == custInvoiceTable.RecId;
custPostInvoice = new CustPostInvoice(custInvoiceTable1);
custPostInvoice.run();
Comments