Monday, May 28, 2018

D365/AX7 - How to create custom workflow participant provider for team


The workflow designer provides you 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 participant provider in order to solve the problem below. 

Problem

We have no option to assign the workflow work item to the team in Microsoft Dynamics AX to get approval from the respective team members.


Solution

Team participant provider (Workflow participant assignment provider)

Workflow participant provider helps to resolve the selected user group to get the associated users, and to resolve security role in Microsoft Dynamics AX to get the users assigned to that role. The resolved users are assigned the workflow work item to get their approval.
The above mentioned problem can be resolved by creating a custom workflow participant provider for team (say Team Participant Provider).

Step#1 Add class for the team participant provider. Add new Item > Code > Class.




Step#2 Implement the class with WorkflowParticipantProvider class. Following two methods need to be implemented in the team participant provider class.

a. getParticipantTokens: Enter the following code to implement the method in custom provider class to get the list of active teams as defined in Microsoft Dynamics AX, to select in workflow designer. 


public WorkflowParticipantTokenList getParticipantTokens()
{
WorkflowParticipantTokenList    participantTokenList = WorkflowParticipantTokenList::construct();
       OMTeam                          omTeam;

       //Get the list of active teams
       while select omTeam
              order by Name asc
where omTeam.IsActive == NoYes::Yes
        {
            participantTokenList.add(omTeam.Name, omTeam.Description);

        }
        return participantTokenList;

}

Please note that here we have team name as the participant token Id, which will be used to resolve users for the workflow.

b. resolve: The resolve method is called to determine what users must be selected as approver of the workflow work item from the selected team i.e. participant token name.

public WorkflowUserList resolve(WorkflowContext _context,
                                    WorkflowParticipantToken _participantTokenName)
{
WorkflowUserList            workflowUserList = WorkflowUserList::construct();
       DirPersonUser               personUser;
       OMTeam                      team;
       DirPartyRelationship        partyRelationship;
       DirRelationshipTypeTable    relationshipTypeTable;
       
       // verify if participant token is set
       if (!_participantTokenName)
       {
              throw error("@SYS105453");
       }

       select firstonly RecId, Name from team
where team.Name == _participantTokenName;

       // verify team exists
       if (!team.RecId)
       {
              throw error(strFmt("Team %1 was not found", _participantTokenName));
       }

       // Get team members of the selected team and add to the workflow user list
       while select User, PersonParty from personUser
              exists join partyRelationship
                     where partyRelationship.ChildParty == personUser.PersonParty
                    && partyRelationship.ParentParty == team.RecId
exists join relationshipTypeTable
                    where relationshipTypeTable.RelationshipTypeId == partyRelationship.RelationshipTypeId
&& relationshipTypeTable.SystemType == DirSystemRelationshipType::TeamMember
{
              workflowUserList.add(personUser.User);
       }

return workflowUserList;

}

Step#3 Add new item > Business Process and Workflow > Workflow Participant Assignment Provider





Step#4 Set the Provider Class property of the TeamParticipantProvider with TeamParticipantProvider class. If the class does not exists in the drop down, you must enter the name of the class manually.




If the property Available for All Workflows is set to Yes, the provider will be applied to all the workflow types. If the property is set to No, the workflow provider will be applicable to only the workflow types added under the node Workflow Types of workflow participant provider.
Set the label and help text property of the provider so you can identify on workflow designer.


Execution

After the relevant model is built, open the workflow designer and go to the assignment settings of the workflow step. Select the Participant in Assignment Type tab and navigate to the next tab for Role based. You can set the Type of participant as the Team participant provider and select a team from dropdown as Participant.


When the workflow is submitted, the work item is assigned to all the users of the selected team.
Similarly, the workflow participant provider can be created for the team leader as well. The resolve method of provider class will be modified as below.

Modify code from:
//code above…
&& relationshipTypeTable.SystemType == DirSystemRelationshipType::TeamMember
//code below…

To:
//code above…
&& relationshipTypeTable.SystemType == DirSystemRelationshipType::TeamLeader
//code below…

In this way, the workflows can be enhanced with the options to assign to other worker/user group apart from user groups and security roles in Microsoft Dynamics AX.

3 comments:

  1. Amazing blog it save my Day, I was having the same business case in one of my project it helps me alot... GOD bless you

    ReplyDelete
  2. Microsoft Security training enhances the knowledge and skills of individuals in various aspects of cybersecurity and securing Microsoft technologies. It helps organizations strengthen their security posture, mitigate risks, and safeguard sensitive information from cyberattacks and unauthorized access.

    ReplyDelete