How can I call a servlet/service call for every workflow Approve and Reject action. | Community
Skip to main content
New Participant
May 16, 2023
Solved

How can I call a servlet/service call for every workflow Approve and Reject action.

  • May 16, 2023
  • 2 replies
  • 806 views

Team,

 

I need to make a service call for every workflow approve and reject actions. Is there any way to capture Approve and Reject actions of workflow.  OR else JS is also fine.

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 ShaileshBassi

Hi @racer3189 

There are multiple ways to handle this case:

Approach I:

As stated by @raushan123 Basically in the next step of the workflow where you are either approving or rejecting it, one can created a process step for reading the args and then based on it perform the next steps 

Sample code for reading the arguments and calling the service is

@Reference ContentApprovalWorkflowService contentApprovalWorkflowService; public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException { if (args.containsKey("PROCESS_ARGS")){ if(args.get("PROCESS_ARGS","string").toString().equalsIgnoreCase('Approved'){ contentApprovalWorkflowService.publish(payload); } contentApprovalWorkflowService.addLog(payload); } }

 

Approach II: Create seperate business logic and there is no need for reading the args.

Based on the selection from the participant or dynamic participant step the respective process step can be called which can call the service using the @Reference Annotation.

 

This approach is ideal when the processing logic for approval and rejection is complex and should be kept segregated.

Hope this helps!

Thanks

2 replies

ShaileshBassi
ShaileshBassiAccepted solution
New Participant
May 16, 2023

Hi @racer3189 

There are multiple ways to handle this case:

Approach I:

As stated by @raushan123 Basically in the next step of the workflow where you are either approving or rejecting it, one can created a process step for reading the args and then based on it perform the next steps 

Sample code for reading the arguments and calling the service is

@Reference ContentApprovalWorkflowService contentApprovalWorkflowService; public void execute(WorkItem item, WorkflowSession session, MetaDataMap args) throws WorkflowException { if (args.containsKey("PROCESS_ARGS")){ if(args.get("PROCESS_ARGS","string").toString().equalsIgnoreCase('Approved'){ contentApprovalWorkflowService.publish(payload); } contentApprovalWorkflowService.addLog(payload); } }

 

Approach II: Create seperate business logic and there is no need for reading the args.

Based on the selection from the participant or dynamic participant step the respective process step can be called which can call the service using the @Reference Annotation.

 

This approach is ideal when the processing logic for approval and rejection is complex and should be kept segregated.

Hope this helps!

Thanks

New Participant
May 16, 2023

Basically, you have to pass action (approve or reject ) through model

and below approve or reject step you have to configure one  custom process step 

and in that custom process step java code.

you have to capture the argument 

String argument = metDataMapargs.get(WORKFLOW_PROCESS_ARGS, String.class);

 based on this you can  find whether it's approved or reject