Saturday, August 6, 2022

Auto submission of workflow X++

Hi folks,

In this blog, I am going to explain how to submit workflow automatically for approval without user interaction in D365 FO.

Requirement:

I got a requirement where in Vendor master data workflow was required to be submitted automatically for approval because Vendors were created through integration and not manually by D365 FO users.

As part of business process, vendor workflow approval process was configured and implemented for finance key users in D365 FO.

Solution:

As soon as Vendors are created through integration, submit workflow action is triggered by applying the below logic. 

 class AutoWorkflowSubmit  
 {  
   public static void main(Args args)  
   {  
     //Get the VendTable RecId for the vendor to submit the workflow  
     RecId recId;  
     try  
     {  
       ttsbegin;  
       //Pass the recId of VendTable in Workflow class that is responsible to trigger the workflow submit action  
       //Activate the workflow  
       Workflow::activateFromWorkflowType(workFlowTypeStr(VendTableChangeProposalWorkflow), recId, "@AccountsPayable:VendChangeProposalSubmit_SubmittedMessage", NoYes::No);  
       //Pass the recId of VendTable in VendTable class that is responsible to update the workflow status as Submitted  
       VendTable::updateWorkflowState(recId,VendTableChangeProposalWorkflowState::Submitted);  
       ttscommit;  
     }  
     catch(exception::Error)  
     {  
       throw Error("Not submitted");  
     }  
   }  
 }  

No comments:

Post a Comment

Enable and Disable Vendor invoice button on PO list and details page X++

Hi folks, This blog will be useful where vendor invoice process is required to be controlled based on certain conditions. Requirements: Proc...