Creating Fullfillment Workflows
This tutorial aims to guide you through the process of creating a fulfillment workflow that can manage the deletion of multiple accounts. Firstly, it receives a list of Business Request Items and performs the deletion operation on each. Additionally, it checks for basic logic, such as verifying if there are any accounts to delete using the line rule.
To create the workflow, we will follow the steps below:
Use the fulfillment workflow template that is available in Workflow Studio.
Familiarize yourself with the basic structure and activities of the provided template.
Add code to delete multiple accounts.
Add line rules and their corresponding code.
Compile and publish the workflows.
This documentation offers comprehensive guidance on developing fulfillment workflows using Workflow Studio. For an overview and foundational concepts of fulfillment workflows, see the article here.
Create a Fulfillment Workflow
In this example, our goal is to create a fulfillment workflow that can handle deleting all input accounts. Follow the instructions below to develop the workflow.
Right-click on the Package node in the Workflow Studio and select New Workflow > Fulfillment Workflow from the context menu to create a new fulfillment workflow.
Upon creation, you will see the fulfillment workflow with the following default activities. Let me give you a brief summary of these activities:
ValidateClaimedBusinessRequestItems: This activity validates the business request items associated with incoming calls from consoles, APIs, etc. It retrieves data from the database to verify the business request items exist and their status. This activity also updates the Fulfillment Process ID for the business request item to indicate the business request that is currently fulfilling the business request item.
SetOperationInputs: This activity extracts the operation input parameters or the business request items against which the fulfillment has to be done.
Drag Operation Activities Here: This is a placeholder where you can drag and drop additional activities into the workflow.
SetBusinessRequestItemStatus: This activity sets the execution status of the business request items, indicating whether it was successful or not.
Save the workflow by clicking on the Save icon in the toolbar and provide a suitable name for the fulfillment workflow. Once you save, the workflow will reload and show you the default activities.
Ensure the workflow name is updated. Click on the Set Operation Inputs Activity and modify the code to set the workflow name correctly. Repeat the same process for SetBusinessRequestItemStatus Activity.
We will perform the delete account operation using the default operation available in EmpowerID. To find the necessary activity, go to the Activities pane, enter the relevant search text, and select the Delete Account Operation from the search results. Afterward, drag and drop the activity to the "Drag Operation Activities Here” placeholder.
Click on the newly added operation activity and provide a suitable name and description.
Enabling an operation is important after adding it. Right-click on the operation and select Enable/Disable option.
After selecting the Enable/Disable option, a popup will appear. Click on the forward arrow (>) to select. Once the desired operations are in the right pane, they are ready to be enabled.
Add some code to the Set Operation Inputs activity in the Implement Method.
List<Guid> targetAccountGuids = CurrentWorkflow.ValidateBRIs.ClaimedBusinessRequestItems.Select(a => a.RequestDataTargetResourceID.Value).Distinct().ToList(); E.TList<C.Account> targetAccounts = Account .GetByAccountGuids(targetAccountGuids); var nonDeletedAccounts=new E.TList<C.Account>(targetAccounts.Where(a => !a.Deleted).ToList()); CurrentWorkflow.DeleteAccounts.TargetAccounts=nonDeletedAccounts; CurrentWorkflow.BusinessRequestItemDictionary = new Dictionary<Guid, BusinessRequestItem>(); foreach (var bri in CurrentWorkflow.ValidateBRIs.ClaimedBusinessRequestItems) { if (!nonDeletedAccounts.Where(a=>a.AccountGUID==bri.RequestDataTargetResourceID.Value).Any()) { bri.ProcessStatus = 4; bri.BusinessRequestItemFulfillmentStatusID=4; } CurrentWorkflow.BusinessRequestItemDictionary[bri.RequestDataTargetResourceID.Value]=bri; }
Add Code to the Implement Method of the SetBusinessRequestItemStatus activity.
List<Framework.Common.Shared.Workflow.OperationExecutionSummary> oplist = CurrentWorkflow.DeleteAccounts.OperationsExecutionSummary; foreach (Framework.Common.Shared.Workflow.OperationExecutionSummary op in oplist) { var bri = CurrentWorkflow.BusinessRequestItemDictionary[op.TargetResourceGUID]; bri.ProcessStatus = 2; if (op.OperationExecuted) { bri.BusinessRequestItemFulfillmentStatusID = 3; //success } else { bri.BusinessRequestItemFulfillmentStatusID = 4; //Fail bri.ProcessStatus = 3; bri.FailedCount += 1; bri.LastFailed = DateTime.UtcNow; bri.NextAttempt = DateTime.UtcNow.AddMinutes(10 * bri.FailedCount * bri.FailedCount); bri.LastFailedError=op.ExecutionResultMessage; } } var businessRequestItems=new E.TList<C.BusinessRequestItem>(CurrentWorkflow.BusinessRequestItemDictionary.Select(a => a.Value).ToList()); BusinessRequestItem.Update(businessRequestItems);
If there are no accounts that need to be deleted, you can make the process more efficient by using a skip rule. This rule will ignore the execution of the added operation. To add a skip rule, simply right-click on the activity and choose Select Skip Rule.
To create a new rule, click on the Create New button.
Click on Add after providing a suitable name to save the rule. Click Close to return to the previous window.
Please choose the recently created rule from the dropdown and apply it to the operation.
Right-click on the operation activity and select Edit_{YourRuleName} from the context menu. Add the following code into the Evaluate method to include skip logic to the skip rule.
return CurrentWorkflow.DeleteAccounts.TargetAccounts==null||CurrentWorkflow.DeleteAccounts.TargetAccounts.Count==0;
Compile and Publish the Workflow
Before we can test the fulfillment workflow, the workflow needs to be published. Publish it to EmpowerID. For more information about it, find more details here.
Link Fulfillment Workflow to an Item Type Action
Once you've created a fulfillment workflow, it's crucial to set up its trigger mechanism. One typical approach is to link it with No Code Flows via Item Type Actions. This method ensures that whenever a certain Item Type action is chosen for a specific business request type, the corresponding configured workflow is automatically activated to perform the designated action.
You can create an Item Type action and select the fulfillment workflow that you created or configured for an existing Item Type action.