How do I Modify the Workflow Work Item Page? | Community
Skip to main content
JonMaguire
Level 3
May 28, 2021
Solved

How do I Modify the Workflow Work Item Page?

  • May 28, 2021
  • 1 reply
  • 1127 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Asutosh_Jena_

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());

 

1 reply

Asutosh_Jena_
Community Advisor
Asutosh_Jena_Community AdvisorAccepted solution
Community Advisor
May 29, 2021

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());