Expand my Community achievements bar.

SOLVED

Check if list of pages are in workflow

Avatar

Level 3

Hi everyone,
I came across a sling job requirement of checking if any of the pages in a list (this list will come from a TSV or CSV file stored in DAM) is in workflow or not and then do the further processing. What are the ways we can try ? And Is there any way of checking that efficiently? (there are going to be around tens of thousands of pages). 

What I have tried : (Please correct me if I'm in the wrong direction)

I was trying Payload Map, but it is returning null in the first line itself. Resource Resolver is working fine.

PayloadMap payloadMap = resourceResolver.adaptTo(PayloadMap.class);
payloadMap.isInWorkflow(resource.getPath(), true/false);

 

Thank You

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Jangra98,

I think using WorkflowStatus class will be the best option. In general you can iterate over the list of pages and get Resource or Page object of each item from the list, and simply adapt it to WorkflowStatus to get information if given page is subject of the workflow.

 

// for Resource object
WorkflowStatus ws = resource.adaptTo(WorkflowStatus.class);
// gives you information if given resource is subject of workflow
ws.isInRunningWorkflow(false);
// gives you list of workflows that current resource is part of
ws.getWorkflows(false);

// the same code for Page object
WorkflowStatus ws = page.adaptTo(WorkflowStatus.class);
ws.isInRunningWorkflow(false);
ws.getWorkflows(false);

 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi @Jangra98,

I think using WorkflowStatus class will be the best option. In general you can iterate over the list of pages and get Resource or Page object of each item from the list, and simply adapt it to WorkflowStatus to get information if given page is subject of the workflow.

 

// for Resource object
WorkflowStatus ws = resource.adaptTo(WorkflowStatus.class);
// gives you information if given resource is subject of workflow
ws.isInRunningWorkflow(false);
// gives you list of workflows that current resource is part of
ws.getWorkflows(false);

// the same code for Page object
WorkflowStatus ws = page.adaptTo(WorkflowStatus.class);
ws.isInRunningWorkflow(false);
ws.getWorkflows(false);