Video blog: How to Create Custom Workflow Participant Provider?

How to create Workflow Participant Provider? 

Introduction: A Workflow Participant Provider in D365FO defines how users or groups are assigned to tasks in a workflow. 

  • Role Assignment: It determines who is responsible for tasks at each workflow step. 
  • Customization: You can create custom providers to set specific rules for assigning participants. 
  • Integration: It works with the workflow framework for dynamic participant assignment based on context. 

Overall, it ensures the right people are involved in the workflow, enhancing efficiency and accountability. 

Scenario: The user wants to assign workflow approval to the manager specified in the customer form, considering that name as the designated manager. 

High level resolution steps 

  • Create a new class for the participant provider. 
  • Implement the WorkflowParticipantProvider class to activate its functionality. 
  • Add a new entry in the Business Process and Workflow section under Workflow Participant Assignment Providers. 
  • In the Workflow Participant Assignment Provider, set the Provider Class property using the WorkflowParticipantProvider class. 
  • In the workflow editor, select the type of participant and choose the participant from the drop-down menu. 

Detailed resolution steps 

Step 1: Add a new class for the participant provider

Step 2: Implement the class with the WorkflowParticipantProvider class. The following two methods need to be implemented in the team participant provider class: 

  1. getParticipantTokens: This method retrieves the list of active participants. 
  1. resolve: This method determines which users should be selected as approvers for the workflow from the list of selected participants. 

Code Snippet: 


internal final class SCSS_EmployeeProjectWorkflowProvider implements WorkflowParticipantProvider 

{ 
    public WorkflowParticipantTokenList getParticipantTokens() 
    {
        WorkflowParticipantTokenList userGroups = WorkflowParticipantTokenList::construct(); 
        userGroups.add("Manager","Team lead"); 
        return userGroups; 
    } 

    public WorkflowUserList resolve(WorkflowContext _context, WorkflowParticipantToken _participantTokenName) 
    { 
        WorkflowUserList                userList             = WorkflowUserList::construct(); 
        UserInfo                        userTable; 
        PartyIProvider                  partyProvider        = PartyProviderFactory::getPartyProvider(); 
        DirPerson                       dirPersonTable;
        SCSS_EmployeeProjectTable       employeeProjectTable = SCSS_EmployeeProjectTable::find(_context.parmRecId()); 

        HcmWorker                       hcmWorker            = HcmWorker::findByPersonnelNumber(employeeProjectTable.Manager); 

        if (!_participantTokenName) 
        { 
            throw error("@SYS105453"); 
        } 
      
        if(employeeProjectTable) 

        { 
            if(_participantTokenName == "Manager") 
            { 
                while select id from userTable 
                { 
                    dirPersonTable = partyProvider.findDirPersonByUserId(userTable.id);

                    if(dirPersonTable.RecId == HcmWorker::find(hcmWorker.RecId).DirPerson().RecId) 

                    { 
                        userList.add(userTable.id); 

                    } 

                } 

            } 

        } 

        return userList; 

    } 

} 
    

Code Explanation: 

The SCSS_EmployeeProjectWorkflowProvider class implements WorkflowParticipantProvider to manage workflow participants for employee projects. 

  1. getParticipantTokens Method: Returns a list of participant roles, specifically “Manager” and “Team lead.” 
  1. resolve Method: Determines eligible approvers based on the provided participant token. If the token is “Manager,” it retrieves the manager’s user ID from the employee project record and adds it to the user list if it matches the current user. 

This class enables dynamic assignment of workflow approvers based on project-specific roles. 

Step 3: Add a new item in the Business Process and Workflow section under Workflow Participant Assignment Provider. Add new item -> Business Process and Workflow -> Workflow Participant Assignment Provider. 

Step 4: Using the WorkflowParticipantProvider class, set the Provider Class property of the WorkflowParticipantAssignementProvider. You must manually enter the class’s name if it does not appear in the drop-down menu. 

Add the workflow type where you need to add this feature. 

Step5: Open the workflow editor, double click the approval node. Click Basic settings -> select Assignment -> Role based -> Select Type of participant & participant. 

Output 

Manager name highlighted in the custom form below. 

Submitted workflow assigned to the Manager name mentioned in the above screenshot.