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!