How to create workflow participant provider and use it in standard and custom workflows.
Hi All,
In this blog I will explain how to create workflow participant provider for custom and standard workflow.
Workflow participant provider helps us to assign workflow approver at runtime instead of hardcoding the approver name under workflow configuration.
Let us say I need to assign the workflow approval to current user who logged in. As soon as the work item is created workflow participant provider class will be triggered and the approvers will be assigned based on the user list.
Let us create one workflow participant provider.
Now let us add the workflow type to workflow assignment provider. For example, I have considered standard timesheet workflow.
Now create one participant provider class which implements WorkflowParticipantProvider - This class will contains main code for the workflow approvers to be assigned at runtime based on the current record.
On this class you need to write two methods resolve and getParticipantTokens.
In resolve method we will mention the name of the participant which will be shown in the workflow configuration form.
In getParticipantToken method we will add the select statement to assign workflow approvers at runtime.
Below is the whole code.
class TSTimesheetWorkflowProvider implements WorkflowParticipantProvider { const str owner = "Current user"; public WorkflowParticipantTokenList getParticipantTokens() { WorkflowParticipantTokenList token = WorkflowParticipantTokenList::construct(); token.add(owner,'CurrentUser'); // you can add multiple paricipant token here. toke.add(owner1,'CurrentUser1'); return token; } public WorkflowUserList resolve(WorkflowContext _context, WorkflowParticipantToken _participantTokenName) { WorkflowUserList userList = WorkflowUserList::construct(); if(!_participantTokenName) { throw error("@SYS105453"); } switch(_participantTokenName) { case owner: userList.add(curUserId()); break; case owner: // add select statement based on the current record. _context argument will have parmRecId. select * from tableName where tablename.RecId == _context.parmRecId(); userList.add(tableName.userId); break; } return userList; } }
Now on the workflow assignment provider map the created class.
Now build and synch the project - Open the timesheet workflow configuration.
Select Assignment type as "Participant".
On the Role based tab select Type of participant and Participant name.
As you can see the Type of participant will be coming from workflow assign provider label and the Participant name coming from the getParticipantToken method.
Now after submission of workflow as soon as the work item is created workflow participant provider will be called and approver will be assigned.
Thanks.
*This post is locked for comments