The reporter and assigned fields are handled differently than a multiple selector, I leave you the script that can work with several. And add some loggers for better visualization in case of error
final issueKey = "PROJ-123"; // Replace this with the correct issue key
// Fetch issue details including summary and custom field (SIM Champion)
def issueResponse = get("/rest/api/3/issue/${issueKey}?fields=summary,customfield_10715")
.header('Content-Type', 'application/json')
.asString()
if (issueResponse.status != 200) {
logger.error("Error fetching issue details. Status: ${issueResponse.status}")
return
}
// Parse the response to get the issue's summary and the SIM Champion field
def issueDetails = new groovy.json.JsonSlurper().parseText(issueResponse.body)
def summary = issueDetails.fields.summary.toString()
def simChampionUsers = issueDetails.fields.customfield_10715 // This is a list of users
// Check if there are any users in the SIM Champion field
if (simChampionUsers) {
// Iterate through each user and send a notification
simChampionUsers.each { user ->
def simChampionaccountId = user.accountId.toString();
// Send notification email to each user in SIM Champion
def resp = post("/rest/api/3/issue/${issueKey}/notify")
.header("Content-Type", "application/json")
.body([
subject: "New SIM Champion Assignment for Issue ${issueKey}",
htmlBody: """<p>Hello,</p>
<p>You have been assigned as SIM Champion for issue ${issueKey}.</p>
<p>Issue Summary: ${summary}</p>
<p>Thank you,<br>Your Jira Team</p>""",
to: [
users: [
[accountId: simChampionaccountId],
]
]
])
.asString();
if (resp.status != 204) {
logger.error("Failed to send notification to user ${simChampionaccountId}. Response: ${resp.status}")
} else {
logger.info("Notification successfully sent to ${simChampionaccountId}")
}
}
} else {
logger.error("No users found in the SIM Champion field for issue ${issueKey}")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.