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