Here is a sample class which is called via Dialog framework to create & post free text invoice using X++ code.
1 public void xtest() 2 { 3 Dialog dialog; 4 DialogField dlgCustAcc; 5 DialogGroup dialogPeriodLengthGroup, dialogPeriodLengthGroup1; 6 DialogField dlgLedgerAcc; 7 ; 8 dialog = new Dialog("Free-Text Invoice"); 9 dialogPeriodLengthGroup1 = dialog.addGroup(‘Cust Table’); 10 dlgCustAcc = dialog.addField(typeid(CustAccount)); 11 dialogPeriodLengthGroup = dialog.addGroup(‘Ledger Table’); 12 dlgLedgerAcc = dialog.addField(typeid(LedgerAccount)); 13 14 15 if (dialog.run()) 16 { 17 if (dlgCustAcc.value() && dlgLedgerAcc.value() != ”) 18 FreeTxtInvoiceCreatePost::main(dlgCustAcc.value(), dlgLedgerAcc.value()); 19 else 20 throw error(strfmt("Either CustAccount or LedgerAccount info is missing.")); 21 } 22 } 23 24 /// <summary> 25 /// The <c>Job_FreeTxtInvoice</c> class is implemented to create/post <c>Free Text Invoice</c>. 26 /// </summary> 27 class FreeTxtInvoiceCreatePost 28 { 29 } 30 31 static void main(CustAccount _custAccount, LedgerAccount _ledgerAccount) 32 { 33 CustInvoiceTable custInvoiceTable; 34 CustInvoiceLine custInvoiceLine; 35 CustTable custTable; 36 LedgerTable ledgerTable; 37 CustPostInvoice custPostInvoice; 38 LineNum lineNum; 39 int i; 40 ; 41 42 /// <summary> 43 /// The <c>CustInvoiceTable</c> logic is implemented to create single <c>Header</c>. 44 /// </summary> 45 ttsbegin; 46 custTable = CustTable::find(_custAccount); 47 custInvoiceTable.initFromCustTable(custTable); 48 custInvoiceTable.insert(); 49 ttscommit; 50 51 /// <summary> 52 /// The <c>CustInvoiceLine</c> logic is implemented to create multiple <c>Invoice Lines</c>. 53 /// </summary> 54 for (i = 1; i <= 100; i++) 55 { 56 ttsbegin; 57 ledgerTable = LedgerTable::find(_ledgerAccount); 58 custInvoiceLine.clear(); 59 custInvoiceLine.initValue(); 60 custInvoiceLine.LedgerAccount = ledgerTable.AccountNum; 61 custInvoiceLine.initFromCustInvoiceTable(custInvoiceTable); 62 custInvoiceLine.AmountCur = 10.00; 63 custInvoiceLine.Description = ‘FreeTxIv’ + int2str(i); 64 custInvoiceLine.TaxItemGroup = ‘full’; 65 custInvoiceLine.ParentRecId = custInvoiceTable.RecId; 66 67 //LINE NUM LOGIC. 68 if(!lineNum) 69 { 70 lineNum = CustInvoiceLine::lastLineNum(custInvoiceLine.ParentRecId); 71 } 72 73 lineNum += 1; 74 custInvoiceLine.LineNum = lineNum; 75 custInvoiceLine.insert(); 76 ttscommit; 77 } 78 79 /// <summary> 80 /// The <c>custPostInvoice</c> class is called for posting <c>Free-TextInvoice.</c> records. 81 /// </summary> 82 custPostInvoice = new CustPostInvoice(custInvoiceTable); 83 custPostInvoice.run(); 84 }