Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How do I Modify the Workflow Work Item Page?

Avatar

Level 3

I'm wanting to modify the Initiator field value on the WORKFLOW INFO tab on the Work Item page in AEM 6.5. Currently it displays the ID of the workflow initiator. I want to change the value to the name of the initiator. I've searched documentation and have dug around in CRX, but I am a bit lost on how to accomplish this. I'm hoping someone can point me in the right direction?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @JonMaguire 

 

createWorkflowInstance() of com.adobe.granite.workflow.core.jcr.WorkflowManager.java class is used to create the workflow instance and populate all the metadata such as (data, history, metaData and workItems node). 

 

public WorkflowImpl createWorkflowInstance(WorkflowModel model, WorkflowData workdata, MetaDataMap metaData, boolean supressWorkitemLoading) throws WorkflowException {
try {
Session jcrSession = (Session)getWorkflowSession().adaptTo(Session.class);
String simpleModelId = getSimpleModelId(model);
Node instance = this.workflowBucketManager.createWorkflowInstanceNode(jcrSession, simpleModelId, "cq:Workflow");
instance.setProperty("modelId", model.getId());
instance.setProperty("modelVersion", model.getVersion());
instance.setProperty("startTime", Calendar.getInstance());
instance.setProperty("initiator", jcrSession.getUserID()); // this is where we read the userid.
instance.setProperty("status", Workflow.State.RUNNING.name());
instance.setProperty("parentInstanceId", "none");
updateMetadata(instance, metaData, false);
instance.addNode("workItems", "nt:unstructured");
workdata.getMetaDataMap().putAll((Map)metaData);
updateWorkflowData(instance, workdata, model.getVariableTemplates());
if (WorkflowUtil.doSave((WorkflowSession)getWorkflowSession()))
jcrSession.save();
return NodeReader.createWorkflow(instance, (WorkflowSession)getWorkflowSession(), this.classLoader, this, this.customDataTypeRegistry);
} catch (RepositoryException re) {
throw new WorkflowException("Cannot create workflow instance", re);
}
}

 By using the below code you can retrieve the user name and set it instead of user id. But this is an OOTB functionality and I will not recommend to do so.

UserManager userManager = resourceResolver.adaptTo(UserManager.class);
Authorizable auth = userManager.getAuthorizable(session.getUserID());
instance.setProperty("initiator", auth.getPrincipal().getName());

 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @JonMaguire 

 

createWorkflowInstance() of com.adobe.granite.workflow.core.jcr.WorkflowManager.java class is used to create the workflow instance and populate all the metadata such as (data, history, metaData and workItems node). 

 

public WorkflowImpl createWorkflowInstance(WorkflowModel model, WorkflowData workdata, MetaDataMap metaData, boolean supressWorkitemLoading) throws WorkflowException {
try {
Session jcrSession = (Session)getWorkflowSession().adaptTo(Session.class);
String simpleModelId = getSimpleModelId(model);
Node instance = this.workflowBucketManager.createWorkflowInstanceNode(jcrSession, simpleModelId, "cq:Workflow");
instance.setProperty("modelId", model.getId());
instance.setProperty("modelVersion", model.getVersion());
instance.setProperty("startTime", Calendar.getInstance());
instance.setProperty("initiator", jcrSession.getUserID()); // this is where we read the userid.
instance.setProperty("status", Workflow.State.RUNNING.name());
instance.setProperty("parentInstanceId", "none");
updateMetadata(instance, metaData, false);
instance.addNode("workItems", "nt:unstructured");
workdata.getMetaDataMap().putAll((Map)metaData);
updateWorkflowData(instance, workdata, model.getVariableTemplates());
if (WorkflowUtil.doSave((WorkflowSession)getWorkflowSession()))
jcrSession.save();
return NodeReader.createWorkflow(instance, (WorkflowSession)getWorkflowSession(), this.classLoader, this, this.customDataTypeRegistry);
} catch (RepositoryException re) {
throw new WorkflowException("Cannot create workflow instance", re);
}
}

 By using the below code you can retrieve the user name and set it instead of user id. But this is an OOTB functionality and I will not recommend to do so.

UserManager userManager = resourceResolver.adaptTo(UserManager.class);
Authorizable auth = userManager.getAuthorizable(session.getUserID());
instance.setProperty("initiator", auth.getPrincipal().getName());