Thursday, May 31, 2018

D365/AX7 – How to create custom workflow hierarchy assignment provider

The workflow designer provides a variety of configuration options to setup workflow as per our business needs. Workflow providers are the key components of the workflows in Microsoft Dynamics AX. These can be used to provide application specific information to the workflow instance at runtime.
You can go through the Workflow Providers Overview for brief introduction related to workflow providers in Microsoft dynamics AX.
We are going to look into the application of workflow hierarchy provider in order to solve the problem below.


Problem

To create a custom workflow hierarchy provider

Solution

Create custom workflow hierarchy provider using workflow hierarchy helper class for default behavior.

Step#1 Add new class for custom workflow hierarchy provider and implement with WorkflowHierarchyProvider class.

class MY_TaskWorkflowHierarchyProvider implements WorkflowHierarchyProvider
{
    const str Workflow_Employee = 'Employee';

    ExpressionDataSource            dataSource;
    WorkflowHierarchyProviderHelper helper;
}

Step#2 Override new method of the provider class as below

protected void new()
{
       helper = WorkflowHierarchyProviderHelper::construct();
dataSource = ExpressionDataSource::newDataSourceDefinition(Workflow_Employee, "@SYS121302");
       helper.setupDataSource(dataSource);
}

public static MY_TaskWorkflowHierarchyProvider construct()
{
       return new MY_TaskWorkflowHierarchyProvider();
}

Step#3 Implement the methods below with the default implementation of the workflow hierarchy provider using WorkflowHierarchyProviderHelper class

public anytype convertUserIdToNodeDataType(userId _userId,
WorkflowContext _workflowContext)
{
return helper.convertUserIdToNodeDataType(_userId, _workflowContext);
}

public ExpressionDataSource getDataSource()
{
return dataSource;
}

public WorkflowHierarchyProviderNode getNextNode(anytype _nodeId,
WorkflowHierarchyLevel _level,
WorkflowContext _workflowContext)
{
return helper.getNextNode(_nodeId, _level, _workflowContext, dataSource);
}

public extendedDataTypeName getNodeDataType()
{
return helper.getNodeDataType();
}

public Set getSupportedDataType()
{
return helper.getSupportedDataType();
}

public anytype convertToNodeDataType(extendedDataTypeName _dataType,
anytype _value,
       WorkflowContext _workflowContext)
{
return helper.convertToNodeDataType(_dataType, _value, _workflowContext);
}


Step#4 Add new workflow hierarchy assignment provider and set the Provider Class property with your custom hierarchy provider class name.





If the property Available for All Workflows is set to Yes, the provider will be applied to all the workflow types.
You can add your workflow type to enable this provider for the selective workflow and set the property Available for All Workflows to No.

Step#5 Build the relevant model.


Execution

Setup the workflow using task workflow hierarchy provider.


You can now add your customizations related to workflow hierarchy in this class.


No comments:

Post a Comment