Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Invoke the Workflow Actions using API(UI clicks)

Avatar

Community Advisor

Hi Team,

By clicking the buttons on the UI we have to do the WF actions.

I am trying to use the WF API to do this.

Is there any way that I can get the WF Running instance details based on the content URL.

Please advice.

Thanks

Uma

7 Replies

Avatar

Level 10

I doubt that but I could be wrong, if its a transient instance then the processing is in memory. Otherwise, it might be stored temporarily under /var but may not be in a processable format

Avatar

Level 10

As Gaurav states - OOTB - this is not supported. However - you can look at invoking a WF from a servlet that gets called when you click a given Button in the AEM UI.

Avatar

Community Advisor

I am able to move the WF from one state to another state by using the WF API with one problem.

By using getAdmistrativeResourceSolver I am able to get all the WF sessions based on WF states.

By using the ServiceUser I am not getting any WF sessions based on state or workItems.

Here is what I am using

Working

ResourceResolver rsreolover=resolverFactory.getAdministrativeResourceResolver(null); (depricated)

session=rsreolover.adaptTo(Session.class);

WorkflowSession wfsession=workflowservice.getWorkflowSession(session) ;

Workflow[] wf=wfsession.getWorkflows("RUNNING");

Not working

ResourceResolver rsreolover=resolverFactory.getServiceResourceResolver(param);

session=rsreolover.adaptTo(Session.class);

WorkflowSession wfsession=workflowservice.getWorkflowSession(session) ;

Workflow[] wf=wfsession.getWorkflows("RUNNING");

Why the service user is not working. How to fix it?

Thanks

Uma

Avatar

Community Advisor

I have used WorkflowSession in my example but with admin user ,. WFsession is returning Null if I use the "serviceUser" 

Thanks

Avatar

Community Advisor

Hi Uma,

You can get WF instances of current page using resource ststus utility

http://localhost:4504/resource-status/editor/<CurrentPage>.2.json?_=1556182853449

e.g.

http://localhost:4504/resource-status/editor/content/AEM64App/en.2.json?_=1556182853449

Get workflow instance and pass to servlet using parameter and get subservice session and adapt to workflow Instance

try {

paramMap.put(ResourceResolverFactory.SUBSERVICE, "readService");

resourceResolver = resourceFactory.getServiceResourceResolver(paramMap);

Session session = resourceResolver.adaptTo(Session.class);

try {

if (session.isLive()) {

response.getWriter().println("Session User is " + session.getUserID());

WorkItem wi = resourceResolver.getResource(

"/var/workflow/instances/server0/2019-04-25/approval_workflow_1/workItems/node1_var_workflow_instances_server0_2019-04-25_approval_workflow_1")

.adaptTo(WorkItem.class);

response.getWriter()

.println("********************* WORKFLOW Current Assingee: " + wi.getCurrentAssignee());

Workflow wf = wi.getWorkflow();

response.getWriter()

.println("*********************Is This WORKFLOW still Active: " + wf.isActive());

}

} catch (Exception e) {

response.getWriter().println("Exception");

} finally {

session.logout();

}

1739839_pastedImage_0.png



Arun Patidar

Avatar

Community Advisor

Thanks for the info related to Resource Status (liked it) Utility but seems like resource status works only for the editors which are like pages,XF .. Is there any way that I can get these details for the assets as well.

Is there way that we can get the same info on the Assets as well?

and I am getting Null when I use this

WorkItem wf = resourceResolver.getResource("/var/workflow/instances/server0/2019-04-22_1/aem-xxxx-publish-workflow_323/workItems/node1_var_workflow_instances_server0_2019-04-22_1_aem-xxxx-publish-workflow_323").adaptTo(WorkItem.class) 

WorkFlow wf = resourceResolver.getResource("/var/workflow/instances/server0/2019-04-22_1/aem-xxxx-publish-workflow_323/").adaptTo(WorkFlow.class)

Both are returning null.

Thanks