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.
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
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.