How to set worfklow end time in AEM6.5 | Community
Skip to main content
tushaar_srivastava
Level 6
April 3, 2023
Solved

How to set worfklow end time in AEM6.5

  • April 3, 2023
  • 3 replies
  • 1789 views

I need to set the workflow end date and time in node.

 

like how I am setting the worfklow initiator name:

String workflowInitiator = workItem.getWorkflow().getInitiator(); if (node.hasNode("jcr:content")) { node.getNode("jcr:content").setProperty("InitiatedBy", workflowInitiator); }

 

How to set the workflow end time.

 

Thanks

 

@arunpatidar   @jagadeesh_prakash 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by tushaar_srivastava

Thank you @arunpatidar  @siva_sogalapalli  for your response really helped me and got to learn the new things reagrding the exection time of workflow.

 

I tried the new way to execute which fulfil my requirement: 

 

Date initiatedDate = new Date(); public static String convertToUtc(Date date) { final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:00.00'Z'"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); return formatter.format(date); } setPropertyForNodeAndChildNodes(archived.getNode(payloadName), "archivedDate", convertToUtc(initiatedDate)); private void setPropertyForNodeAndChildNodes(Node node, String propertyName, String propertyValue) throws RepositoryException { try { if (node.hasNode("jcr:content")) { node.getNode("jcr:content").setProperty(propertyName, propertyValue); } NodeIterator childNodes = node.getNodes(); while (childNodes.hasNext()) { Node childNode = childNodes.nextNode(); setPropertyForNodeAndChildNodes(childNode, propertyName, propertyValue); } } catch (RepositoryException e) { loggerService.postLog(LogLevel.ERROR, "RepositoryException exception occurred at :: {}" + node.getPath()); }

 

 

3 replies

Siva_Sogalapalli
Community Advisor
Community Advisor
April 3, 2023

If you want to complete the step automatically after certain time, you can advance workflow step which completes the workflow:

// querying work items
WorkItem[] workItems = wfSession.getActiveWorkItems();
// getting routes
List<Route> routes = wfSession.getRoutes(workItem);
// completing or advancing to the next step
wfSession.complete(workItem, routes.get(0));

https://experienceleague.adobe.com/docs/experience-manager-64/developing/extending-aem/extending-workflows/workflows-program-interaction.html?lang=en#using-the-workflow-java-api 

tushaar_srivastava
Level 6
April 3, 2023

Hi @siva_sogalapalli , Thankyou for your response.
But the problem here is need to set the workflow end date and time in node.

Siva_Sogalapalli
Community Advisor
Community Advisor
April 3, 2023

@tushaar_srivastava who is going to set the workflow end date- is that author through workflow dialog or you need to set through programatically when the workflow is initiated? 

Also, just to understand better, can you share more details about the workflow steps like when you set end date, should the workflow execute all the steps? or just abort/complete steps without executing the other steps.

 

arunpatidar
Community Advisor
Community Advisor
April 3, 2023

Hi @tushaar_srivastava 
What do you mean by end time for workflow?

Could you please explain in details with use case?

Arun Patidar
tushaar_srivastava
Level 6
April 3, 2023

Hi @arunpatidar  Thanks for your response.

Sure So I have created a process step where I a move node from one path to another path :

 


public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) throws WorkflowException {
  String payload = workItem.getWorkflowData().getPayload().toString();
  ResourceResolver resourceResolver = resourceResolverUtil.getResourceResolver();
  Session session = resourceResolver.adaptTo(Session.class);
  Page rootPage = resourceResolver.getResource(payload).adaptTo(Page.class);
  ReplicationOptions replicationOptions = new ReplicationOptions();
  if (rootPage != null && payload.startsWith(ROOT_PATH)) {
    String workflowInitiator = workItem.getWorkflow().getInitiator();
    List < String > list = new ArrayList < > ();
    list.add(payload);
    Iterator < Page > childPages;
  }
  try {
    Node payloadNode;
    if (session != null) {
      payloadNode = session.getNode(payload);
      //Move logic page from one source to destiantion setPropertyForNodeAndChildNodes(archived.getNode(payloadName), "initiatedBy", workflowInitiator);
    }
    session.save();
    resourceResolver.close();
  }
}

private void setPropertyForNodeAndChildNodes(Node node, String propertyName, String propertyValue) {
  try {
    if (node.hasNode("jcr:content")) {
      node.getNode("jcr:content").setProperty(propertyName, propertyValue);
    }
    NodeIterator childNodes = node.getNodes();
    while (childNodes.hasNext()) {
      Node childNode = childNodes.nextNode();
      setPropertyForNodeAndChildNodes(childNode, propertyName, propertyValue);
    }
  }

 

And like how we are setting programatically the "initiatedBy" and the value is workflow initiator,

Similarly I need to set the valuse "initiatedDate" and the value would be Workflow executed date and time.

arunpatidar
Community Advisor
Community Advisor
April 3, 2023
tushaar_srivastava
tushaar_srivastavaAuthorAccepted solution
Level 6
April 5, 2023

Thank you @arunpatidar  @siva_sogalapalli  for your response really helped me and got to learn the new things reagrding the exection time of workflow.

 

I tried the new way to execute which fulfil my requirement: 

 

Date initiatedDate = new Date(); public static String convertToUtc(Date date) { final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:00.00'Z'"); formatter.setTimeZone(TimeZone.getTimeZone("GMT")); return formatter.format(date); } setPropertyForNodeAndChildNodes(archived.getNode(payloadName), "archivedDate", convertToUtc(initiatedDate)); private void setPropertyForNodeAndChildNodes(Node node, String propertyName, String propertyValue) throws RepositoryException { try { if (node.hasNode("jcr:content")) { node.getNode("jcr:content").setProperty(propertyName, propertyValue); } NodeIterator childNodes = node.getNodes(); while (childNodes.hasNext()) { Node childNode = childNodes.nextNode(); setPropertyForNodeAndChildNodes(childNode, propertyName, propertyValue); } } catch (RepositoryException e) { loggerService.postLog(LogLevel.ERROR, "RepositoryException exception occurred at :: {}" + node.getPath()); }