Thursday, May 31, 2018

D365/AX7 – Add validation before workflow approval action

This blog will provide you a solution to add validation before the user performs any approval action on the assigned workflow task


Problem

To add validation before the user performs any approval action on the workflow item.


Solution

Add custom workflow work item action manager class.

Step#1 Add a new class extending the class WorkflowWorkItemActionManager

class MY_TaskWorkflowActionManager extends WorkflowWorkItemActionManager
{

}


Step#2 Add the code below to the class

public static void main(Args _args)
{
MY_TaskWorkflowActionManager taskWorkflowActionManager = new MY_TaskWorkflowActionManager();
       
taskWorkflowActionManager.parmCaller(_args.caller());

if(_args.record() && _args.record().TableId == tableNum(MY_TaskTable))
{
if(taskWorkflowActionManager.validate())
{
       taskWorkflowActionManager.parmArgs(_args);
taskWorkflowActionManager.run();
}
       else
       {
              throw error("Task must be valid to perform the action");
       }
}
else
       {
              throw error("Invalid action requested");
}
}

public boolean validate()
{
boolean ret;

       //Add your validation here...

       return ret;

}


Step#3 Go to the action menu item of the above modified outcome and set the property Object with your custom workflow action manager class name




And that’s it. You can similarly use this action manager class for other outcomes of your workflow approval too.

1 comment: