Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can we force an approval notification?

JordanJ January 7, 2022

I'm using the following code to run in a scriptrunner mail handler:

 

//CREATE the query for approvals
ApprovalQuery query = approvalService.newQueryBuilder().issue(issue.id).build();
PagedResponse<Approval> approvals = approvalService.getApprovals(user, query)
log.warn("Incoming mail handler | approvals.getResults() = ${approvals.getResults()}")

//get the last approval- the pending one
Approval unansweredapproval = approvals.results[-1]
log.warn("Incoming mail handler | approvalService.canAnswerApproval(user, unansweredapproval) = ${approvalService.canAnswerApproval(user, unansweredapproval)}")

//Execute the approval
String decision = "approve"
log.warn("Incoming mail handler | decision = ${decision}")
ApprovalDecisionType decisionType = decision.contains("approve") ? ApprovalDecisionType.APPROVED : ApprovalDecisionType.REJECTED
log.warn("Incoming mail handler | decisionType = ${decisionType}")
def answer = approvalService.answerApproval(user, unansweredapproval, decisionType)

 

For some reason, when this is executed via mail handler or listener, it breaks future notifications.  Ideally, I'd like it not to break notifications but for now, how can I force send a notification?

 

If I run this directly in the scriptrunner console, it works fine and everything is ok.  

1 answer

3 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 7, 2022

Hi @JordanJ

I understand that you want to send notifications to the Approvers to ensure that they approve the tickets. Is this correct?

If so, you will need to get the Approval details by using the REST Endpoint and filter it to get the Approver's email addresses. An example of this REST Endpoint code is available in the Adaptavist Library.

Next, you can, for example, use the Escalation Service to invoke the REST Endpoint to get the email addresses of the Approvers and send the email notifications to the Approvers. An example code for this is also available in the Adaptavist Library.

I hope this helps to answer your question. :)

Thank you and Kind Regards,

Ram

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.13.13
TAGS
AUG Leaders

Atlassian Community Events