def notificationPayload = [
subject: "A request has been raised at IT helpdesk that needs your approval.",
textBody: "Kindly follow the link and provide a response to the request.https://tideaccount.atlassian.net/servicedesk/customer/portal/8/{{issue.key}}",
to: [
users: customFieldValue.collect { user -> [accountId: user.accountId] }
]
]
import groovy.json.JsonOutput
def issueKey = issue.key def ApproversId = "customfield_10852" def requestParticipantsFieldId = "customfield_10849"
def issueResponse = get('/rest/api/2/issue/' + issueKey) .header('Content-Type', 'application/json') .asObject(Map)
if (issueResponse.status != 200) { return }
def issueDetails = issueResponse.body def customFieldValue = issueDetails.fields[ApproversId]
if (!customFieldValue) { return }
def notificationPayload = [ subject: "A request has been raised at IT helpdesk that needs your approval.", textBody: "Kindly follow the link and provide a response to the request.https://tideaccount.atlassian.net/servicedesk/customer/portal/8/{{issue.key}}", to: [ users: customFieldValue.collect { user -> [accountId: user.accountId] } ] ]
def notifyResponse = post("/rest/api/2/issue/${issueKey}/notify") .header("Content-Type", "application/json") .body(JsonOutput.toJson(notificationPayload)) .asString()
if (!(notifyResponse.status >= 200 && notifyResponse.status < 300)) { return }
def requestParticipantsValue = customFieldValue.collect { user -> [accountId: user.accountId] }
def updatePayload = [ fields: [ (requestParticipantsFieldId): requestParticipantsValue ] ]
def updateResponse = put("/rest/api/2/issue/${issueKey}") .header("Content-Type", "application/json") .body(JsonOutput.toJson(updatePayload)) .asString()
if (!(updateResponse.status >= 200 && updateResponse.status < 300)) { return }