Hi All,
I have a usecase to terminate the workflow initiated on a page if a condition check within a custom process step in that workflow is not met. Tried using terminate option but it doesn't have an option to send a custom error message that needs to displayed on the page as a reason for termination.
Please let me know if there is a way we can achieve it.
Thanks
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @sagarkmr,
If you are talking about /libs/cq/workflow/admin/console/content/failures.html page, you can take a look into:
I see that it reads failureMessage property from the work item metadata map.
Try to do the following:
workItem.getMetaDataMap().put("failureMessage", "Custom message");
workflowSession.terminateWorkflow(workItem.getWorkflow());
Best regards,
Kostiantyn Diachenko.
Thanks konstantyn_diachenko. Will check this and confirm.
Views
Replies
Total Likes
Hi @sagarkmr
you can terminate a workflow using the workflowSession.terminateWorkflow(workflow) approach to terminate the workflow programmatically and provide a user-visible message.
Workflow workflow = workflowSession.getWorkflow(item.getWorkflow().getId());
workflowSession.terminateWorkflow(workflow);
you can send an aem inbox notification as well using below code:
String message = "The provided path is invalid or does not exist: " + path;
InboxNotification inboxNotification = inboxNotificationSender.buildInboxNotification();
inboxNotification.setTitle("Invalid Path Notification");
inboxNotification.setContentPath(path);
inboxNotification.setAssignee(user);
inboxNotification.setMessage(message);
inboxNotificationSender.sendInboxNotification(adminResolver, inboxNotification);
or as @konstantyn_diachenko suggested, You can utilize the workflow metadata (MetaDataMap) to set a termination message, which users can view in the Workflow Instances or AEM logs.
workflow.getMetaDataMap().put("terminationMessage", "The specified path does not exist: " + path);
Hope this helps!
Thanks abhishekanand_. Will try this.
Views
Likes
Replies