Utility code for submitting the Free text invoice (FTI) to wokflow using code AX 2012

Hi Guys

This post targeting developers and help them submitting the document like free text invoice to workflow automatically using code.

 static void WorkflowAutoSubmit(Args _args)  
 {  
   WorkflowVersionTable  workflowVersionTable;  
   custInvoiceTable _custInvoiceTable;  
   boolean submited = true;  
   workflowVersionTable = Workflow::findWorkflowConfigToActivateForType(  
                       workFlowTypeStr(CustFreeTextInvoiceTemplate),  
                       _custInvoiceTable.RecId,  
                       _custInvoiceTable.TableId);  
   if (_custInvoiceTable.RecId  
   && workflowVersionTable.RecId  
   && _custInvoiceTable.WorkflowApprovalState == CustFreeInvoiceWFApprovalState::NotSubmitted)  
   {  
     // submitting to workflow; if auto workflow submission is required on journal.  
     Workflow::activateFromWorkflowType(  
             workFlowTypeStr(CustFreeTextInvoiceTemplate),  
             _custInvoiceTable.RecId,  
             "auto submit to workflow",  
             false,  
             curUserid());  
     custInvoiceTable::setWorkflowState(_custInvoiceTable.RecId, CustFreeInvoiceWFApprovalState::Submitted);  
     info("invoice submitted to workflow");  
   }  
   else  
   {  
     submited = false;  
   }  
 }  

Thanks
Happy Daxing 🙂

Utility code for creating the Free text invoice (FTI) in AX 2012

Hi Guys,

This post targeting developers and help creating free text invoice from code in dynamics ax 2012

 static void SimpleFtiCreation(Args _args)  
 {  
   custInvoiceTable custInvoiceTable;  
   custInvoiceLine custInvoiceLine;  
   custTable custTable;  
   int lineNum;  
   try  
   {  
     /// <summary>  
     ///   The <c>CustInvoiceTable</c> logic is implemented to create single <c>Header</c>.  
     /// </summary>  
     ttsbegin;  
     custInvoiceTable.clear();  
     custTable = CustTable::find("Test");  
     custInvoiceTable.initFromCustTable(custTable);  
     custInvoiceTable.InvoiceDate = systemDateGet();  
     custInvoiceTable.insert();  
     custInvoiceLine.clear();  
     custInvoiceLine.initValue();  
     custInvoiceLine.initFromCustInvoiceTable(custInvoiceTable);  
     custInvoiceLine.LedgerDimension = 89897878;  
     custInvoiceLine.DefaultDimension = 67676767;  
     custInvoiceLine.Quantity = 100;  
     custInvoiceLine.UnitPrice = 2.5;  
     custInvoiceLine.AmountCur = 250;  
     custInvoiceLine.Description = strFmt("Subscription %1", "Test") ;  
     custInvoiceLine.InvoiceTxt = strFmt("Subscription %1" , "Test") ;  
     custInvoiceLine.ParentRecId = custInvoiceTable.RecId;  
     custInvoiceLine.editReasonCode(true, 'Device Sub');  
     custInvoiceLine.editReasonComment(true, 'Device Subscription');  
     //LINE NUM LOGIC.  
     if(!lineNum)  
     {  
       lineNum = CustInvoiceLine::lastLineNum_W(custInvoiceLine.ParentRecId);  
     }  
     lineNum += 1;  
     custInvoiceLine.LineNum = lineNum;  
     custInvoiceLine.insert();  
     ttscommit;  
     //just to be sure for proper distributions  
     SourceDocumentProcessor::submitSourceDocumentLinesForHeader(custInvoiceTable.SourceDocumentHeader);  
   }  
   catch(exception::Error)  
   {  
   }  
 }