Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

How to add pages/assets to a running workflow ?

Avatar

Level 2

Hi All,

Is there any way to achieve the below requirement.would be grateful for your prompt reply.

Requirement:

1. Requester starts workflow in AEM assets by selecting a word or a pdf document. Requester also selects a schedule publish date/time.
2. Document has description for pages to be built in AEM.
3. Assigns the workflow to a content Editor to build pages from the steps in the document.
4. Content Editor builds pages in AEM and now wants to attach to the running workflow job.
5. Editor adds the files to the job and the workflow proceeds for review.
6. Reviewer could accept or send back review comments to Editor.
7. Editor makes changes and could potentially add/remove pages compared to what were in the first review cycle.
8. Approver approves the job and workflow proceeds to the publish step which is scheduled.
9. Workflow publishes the page when the time arrives.
10. Pages could already be in an active (running) workflow. When Authors attempt starting a new workflow with such pages, the workflow must end with an email (or some sort of notification) that the page attached to this workflow was found already being processed in another workflow.
11. Check for pages that are locked. If a workflow finds Editor has added a locked page to the workflow, then workflow should terminate itself with a notification to the Initiator/Requester/Editor.

 

Steps #5 & #7
Approach 1: Create a Workflow package manually and add/remove files from it manually.
Approach 2: Create Workflow package programatically and add/remove files from it programatically.
Approach 3: Create a Workflow package manually and add/remove files from it programatically.
Create a dialog participant step in the workflow to browse pages and update the workflow package programatically using Page API/Node API.

Suggest the best approach or any new way to achieve this?


Steps #10 & #11
Approach to achieve these senarios?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @nandini559,

Below response is with respect to the requirement listed + validation required on the resources to be activated + possibilities with OOB Workflow set up.

For the query "attach pages to the running workflow" - This is not possible. This is because, the flow starts by triggering workflow on an Asset-> word or pdf document, which remains as Payload through out the Workflow and it is not possible to directly amend the Payload.  (for our publish process step to act upon in the same workflow)

For this reason,

  • We can create one separate workflow model for handling review process + scheduled activation. 
  • Original workflow which is triggered on a document will capture the resources to be activated and for handling the validation and hence to activate by calling workflow model created above.

To locate the resources to be activated to the workflow:

  • Create dialog participant step with Touch UI dialog having pathfield as multifield resource.

For validations on resources and hence activate:

  • Create a process step which will perform the below
    • Get the list of resources(configured in dialog participant step) from the history. (WorkItem's MetaDataMap)
    • For each of the resources (via iteration)
      • Adapt the resource to a Page to check if the page is in locked state -> page.isLocked() #11
      • Using WcmWorkflowService(com.day.cq.wcm.workflow.api.WcmWorkflowService), check if the resource is already in workflow -> wcmWFService.isInWorkflow(resource path) #10
      • If both the validation is through(as indicated by a flag variable), trigger workflow using wfSession.startWorkflow(wfModel, wfData)
        • wfModel -> Create WorkflowModel object from separate workflow model (created for review and scheduled Activation process step)
        • wfData - Create WorkflowData with resource path which is through both the validation.

By this way, separate workflow instance will be created for each of the validated resources.

API for creating Workflow Package is not exposed as service OOB in which case, we can create single workflow instance pertaining to the workflow package path. (I will explore other options around this and update this thread)

In brief, below is the high level flow

  • Workflow is triggered on a document (which has inputs to create pages)
  • Assigned to Content Author(Dialog Participant Step) -> Performs authoring/manual activity outside WF and completes the step by providing list of resources in dialog
  • Process Step -> custom process step performing above mentioned actions. (Another workflow model will be called for each of the validated resources)

Rough snippet from custom Workflow process step:

 

List<HistoryItem> historyItems = wfSession.getHistory(item.getWorkflow());
		for (HistoryItem history : historyItems) {
			MetaDataMap workItemMetaMap = history.getWorkItem().getMetaDataMap();
			String[] pathFieldValues = workItemMetaMap.get("pathFieldMulti", String[].class); // pathFieldMulti holds the array of paths authored in Dialog participant step
			if (null != pathFieldValues) {
				for (String pathField : pathFieldValues) {
					boolean wfFlag = true;
					if (null != pathField) {
						Resource pathResc = rescResolver.resolve(pathField);
						Page pathPageObj = pathResc.adaptTo(Page.class);
						if (null != pathPageObj) {
							if (pathPageObj.isLocked()) {
								wfFlag = false;
								LOG.debug("Page is locked");
							}
						}
						if (wcmWFService.isInWorkflow(pathField)) {
							wfFlag = false;
							LOG.debug("Page is in WF already");
						}
						if (wfFlag) {
							WorkflowModel wfModel = getWorkflowModel(wfSession);
							WorkflowData wfData = getWorkflowData(wfSession, pathField);
							startWorkflow(wfSession, wfModel, wfData);
						}

					}
				}
			}

		}
private void startWorkflow(WorkflowSession wfSession, WorkflowModel wfModel, WorkflowData wfData) {
		try {
			wfSession.startWorkflow(wfModel, wfData);
		} catch (WorkflowException e) {
			LOG.error("Unable to start workflow={}", e.getMessage());
		}
	}

	private WorkflowData getWorkflowData(WorkflowSession wfSession, String pathFieldVal) {
		WorkflowData wfData = wfSession.newWorkflowData("JCR_PATH", pathFieldVal);
		return wfData;
	}

	private WorkflowModel getWorkflowModel(WorkflowSession wfSession) {
		WorkflowModel wfModel = null;
		try {
			wfModel = wfSession.getModel(ACTIVATION_WF);
		} catch (WorkflowException e) {
			LOG.error("Unable to create WF Model={}", e.getMessage());
		}
		return wfModel;
	}

 

wfpackage.png

View solution in original post

6 Replies

Avatar

Employee

You can create a launcher which triggers the workflow when requester selects a word or PDF document and that workflow can be assigned to content editor for further processing.

 

See [0] for detailed information on launcher part.

 

[0]: https://helpx.adobe.com/experience-manager/using/Workflows.html#UsingWorkflowLauncher

 

 

 

Avatar

Level 2
Thanks for the reply, Can you brief a little more on how to achieve this ?

Avatar

Correct answer by
Community Advisor

Hi @nandini559,

Below response is with respect to the requirement listed + validation required on the resources to be activated + possibilities with OOB Workflow set up.

For the query "attach pages to the running workflow" - This is not possible. This is because, the flow starts by triggering workflow on an Asset-> word or pdf document, which remains as Payload through out the Workflow and it is not possible to directly amend the Payload.  (for our publish process step to act upon in the same workflow)

For this reason,

  • We can create one separate workflow model for handling review process + scheduled activation. 
  • Original workflow which is triggered on a document will capture the resources to be activated and for handling the validation and hence to activate by calling workflow model created above.

To locate the resources to be activated to the workflow:

  • Create dialog participant step with Touch UI dialog having pathfield as multifield resource.

For validations on resources and hence activate:

  • Create a process step which will perform the below
    • Get the list of resources(configured in dialog participant step) from the history. (WorkItem's MetaDataMap)
    • For each of the resources (via iteration)
      • Adapt the resource to a Page to check if the page is in locked state -> page.isLocked() #11
      • Using WcmWorkflowService(com.day.cq.wcm.workflow.api.WcmWorkflowService), check if the resource is already in workflow -> wcmWFService.isInWorkflow(resource path) #10
      • If both the validation is through(as indicated by a flag variable), trigger workflow using wfSession.startWorkflow(wfModel, wfData)
        • wfModel -> Create WorkflowModel object from separate workflow model (created for review and scheduled Activation process step)
        • wfData - Create WorkflowData with resource path which is through both the validation.

By this way, separate workflow instance will be created for each of the validated resources.

API for creating Workflow Package is not exposed as service OOB in which case, we can create single workflow instance pertaining to the workflow package path. (I will explore other options around this and update this thread)

In brief, below is the high level flow

  • Workflow is triggered on a document (which has inputs to create pages)
  • Assigned to Content Author(Dialog Participant Step) -> Performs authoring/manual activity outside WF and completes the step by providing list of resources in dialog
  • Process Step -> custom process step performing above mentioned actions. (Another workflow model will be called for each of the validated resources)

Rough snippet from custom Workflow process step:

 

List<HistoryItem> historyItems = wfSession.getHistory(item.getWorkflow());
		for (HistoryItem history : historyItems) {
			MetaDataMap workItemMetaMap = history.getWorkItem().getMetaDataMap();
			String[] pathFieldValues = workItemMetaMap.get("pathFieldMulti", String[].class); // pathFieldMulti holds the array of paths authored in Dialog participant step
			if (null != pathFieldValues) {
				for (String pathField : pathFieldValues) {
					boolean wfFlag = true;
					if (null != pathField) {
						Resource pathResc = rescResolver.resolve(pathField);
						Page pathPageObj = pathResc.adaptTo(Page.class);
						if (null != pathPageObj) {
							if (pathPageObj.isLocked()) {
								wfFlag = false;
								LOG.debug("Page is locked");
							}
						}
						if (wcmWFService.isInWorkflow(pathField)) {
							wfFlag = false;
							LOG.debug("Page is in WF already");
						}
						if (wfFlag) {
							WorkflowModel wfModel = getWorkflowModel(wfSession);
							WorkflowData wfData = getWorkflowData(wfSession, pathField);
							startWorkflow(wfSession, wfModel, wfData);
						}

					}
				}
			}

		}
private void startWorkflow(WorkflowSession wfSession, WorkflowModel wfModel, WorkflowData wfData) {
		try {
			wfSession.startWorkflow(wfModel, wfData);
		} catch (WorkflowException e) {
			LOG.error("Unable to start workflow={}", e.getMessage());
		}
	}

	private WorkflowData getWorkflowData(WorkflowSession wfSession, String pathFieldVal) {
		WorkflowData wfData = wfSession.newWorkflowData("JCR_PATH", pathFieldVal);
		return wfData;
	}

	private WorkflowModel getWorkflowModel(WorkflowSession wfSession) {
		WorkflowModel wfModel = null;
		try {
			wfModel = wfSession.getModel(ACTIVATION_WF);
		} catch (WorkflowException e) {
			LOG.error("Unable to create WF Model={}", e.getMessage());
		}
		return wfModel;
	}

 

wfpackage.png

Avatar

Level 2

Hi @Vijayalakshmi_S Thanks a lot for the reply and there is one more question. As per my understanding here we are adding the resources to the multi-field and in the next step we are looping through the list and calling another workflow model on valid resources. But here if the reviewer sends back to modify the pages , can the editor be able to add/remove pages from the multi field(referring to step 6 and 7 from my question)? If so how to retain/get back the values which are stored in history to multi field in the dialog. Is this possible / any other way to achieve this reject scenario?

Avatar

Community Advisor

Hi @nandini559,

Dialog that we are associating to a step in Workflow is specific to that step and is included in the Work Item via Dialog Injection.

We cannot retain the values on any further step having the same dialog.

Given this, review cannot be done on the list of resources as such. (as there is no means for the next step/participant to know the list of resources selected for activation)

 

That's why I have suggested to have review step + activation process in separate workflow model. In which case, review will happen on the individual resources.