I am trying to create a Scriptrunner Listener that will send an email notification to the user that is in a custom people picker field called "SIM Champion". I have tried multiple options but cannot get the notification to be sent. If I replace this custom field with a standard field like Assignee or Reporter then the notification gets sent. I can't figure out what the issue is with the custom people picker field. The following is my latest script. Multiple users can be selected in the SIM Champion field but even if I restrict it to one selection I still receive errors.
{
final summary = issue.fields.summary.toString();
final issueKey = issue.key;
final simChampionFieldId = "customfield_11084";
final simChampionaccountId = issue.fields[simChampionFieldId]?.accountId?.toString();
// Prepare the notification email with dynamic issue key and summary
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>Please be advised that you have been assigned as SIM Champion for the issue ${issueKey}.</p>
<p>Issue Summary: ${summary}</p>
<p>Thank you,<br>Your Jira Team</p>""",
to: [
users: [
[accountId: simChampionaccountId],
]
]
])
.asString();
}