Thursday, January 25, 2024

Workflow submit through X++ code in D365 F&O

Please find the below code to auto submit workflow through X++ code. here you can just change the table name based on the functionality you are working. in my case I have used ProjBudgetRevision. 


 //Check whether we have a Active workflow on the table.

            WorkflowVersionTable workflowVersionTable = Workflow::findWorkflowConfigToActivateForType(workFlowTypeStr(ProjBudgetRevision),

                                                                             projBudRevision.RecId,

                                                                             projBudRevision.TableId);


            //If workflow is active then submit the workflow.

            if (projBudRevision.RecId && workflowVersionTable.RecId)

            {

                //submitting to workflow

                Workflow::activateFromWorkflowType( workFlowTypeStr(ProjBudgetRevision),

                                                projBudRevision.RecId,

                                                "@AutomaticWorkflowSubmit",

                                                false,

                                                curUserid());

                //Update revison workflow status to submit

                ProjBudgetRevision::updateProjBudgetRevisionStatus(projBudRevision.RecId, ProjBudgetRevisionWFStatus::Submitted);

            }

No comments:

Post a Comment