I came across a requirement from a customer who wants to dynamically assign Approvers in a Workflow based on the profiled category of a content in WCM 8.5. Basically, in the Approval Stage of the workflow, the approver should be assigned dynamically based on some logic. This can be easily achieved by using a Custom Workflow Action.
Here is the sample eclipse web project that I created for Custom Workflow Action :
The logic to assign Approvers based on category name is found under MyCustomWorkFlowAction.execute() method. For more details on manipulating the members and groups, please refer the sample code provided in this article :
You should do the following to test the project:
1. Import the project in Eclipse. Export the application as a war file. Install the war file in Websphere Integrated Console. Start the project application.
2. In Portal, login as Administrator. Under 'Web Content' or any library, create a Taxonomy : Locations. Under that create 3 categories : India, United States, Australia.
3. Create a Approver group : India with a user member : India, Australia with a user : Australia. Create an author group user1 with a user : user1.
4. Provide editor access to Approver group - India, Australia and author group - user1.
5. Create a Workflow Action as shown below.
6. Create a Workflow Stage ApprovalStage with Run on Entering Stage set as CustomCategoryAction.
7. Create a Workflow CustomWF with stages - Draft, ApprovalStage, Publish.
8. In the Workflow Draft Stage, under the Workflow Defined Access, uncheck all the Inheritance check box and add Authors group in Editor, reviewer.
9. In the Workflow ApprovalStage, under the Workflow Defined Access, uncheck all the Inheritance check box and don't assign any Approver. The Custom Workflow Action will dynamically add the approvers based on the category name.
10. Create a sample Authoring Template(AT) with workflow as CustomWF.
11. Login as user1, using the AT, create 3 content - IndiaContent profiled with Category (Locations/India), UnitedStatesContent (category: Locations/United States), AustraliaContent(category : Locations/Australia). The contents are in draft state.
12. Submit the content IndiaContent, AustraliaContent. CustomWF action gets invoked and it assigns India/Australia Approver group. Login as user India/Australia, you should be able to see the corresponding content under 'My Pending Approvals'. Publish or Reject the content.
13. Submit the content UnitedStatesContent. CustomWF is unable to find United States group, hence it moves the content to Previous Workflow stage.