Expand my Community achievements bar.

SOLVED

Workflows: Get initiator in a workflow route

Avatar

Level 4

In an OR step for a workflow, I need to know the initiator user to decide if the route should be true or false, based on user roles.

In a workflow step, I can do this:

public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException { … UserManager userManager = AccessControlUtil.getUserManager(workflowSession.getSession()); Authorizable initiator = userManager.getAuthorizable(workItem.getWorkflow().getInitiator()); … }

Note: in a workflow step, if I do ‘workflowSession.getUser()’ I always get ‘admin’ user, and it’s not what I want.

But, as stated in [1] by David McMahon, in an OR step for a workflow, only the workflowData, jcrSession, and workflowSession objects are available to be used within the check() function (not the workItem).

How can I get the initiator user in a workflow route?

[1] http://blogs.adobe.com/dmcmahon/2013/03/26/cq5-failure-running-script-etcworkflowscriptscaworkitem-e...

1 Accepted Solution

Avatar

Correct answer by
Level 10

Instead of args.put  can you try  workflowData.getMetaDataMap().put( "initiator", workItem.getWorkflow().getInitiator()) ;

View solution in original post

4 Replies

Avatar

Level 1

Did you try to add a process step earlier in the model that set the metadata with the initiator ?  That would probably the easiest to solve as then in your or-split you can access the metadata via the workflowData

Avatar

Level 4

Thank you tygeBSL. I've tried this in the first workflow step:

public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap args) throws WorkflowException { ... args.put("initiator", workItem.getWorkflow().getInitiator()); ... }

But in route code I can't write the initiator to the log:

if(workflowData.getMetaDataMap().containsKey("initiator")){ String initiator = (String)workflowData.getMetaDataMap().get("initiator"); log.info("initiator: " + initiator); }

containsKey("initiator") returns false. Am I forgetting something?

Thank you very much!

Avatar

Correct answer by
Level 10

Instead of args.put  can you try  workflowData.getMetaDataMap().put( "initiator", workItem.getWorkflow().getInitiator()) ;

Avatar

Level 4

Perfect! Now it works!

Thank you very much! :-)