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.