Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

[Scriptrunner] - Send an email notification to multiple users pulled form a user-picker field.

Sphinx13 November 1, 2022

Hello all!

I have a few script listeners that send out notifications to certain users, and they're working fine with a single user.

Now, I need to pull users from a user-picker field and send notification to them. 

The API for the notification states this as a possible parameter for sending notifications:

Array<UserDetails>
List of users to receive the notification
example=
{
"accountId": "<string>"
}

 
This is the code I have. 'Approvers' is the custom field I need to pick users froms

 

def issueKey = issue.key

def result = get("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.asObject(Map)

def approvers = result.body.fields.customfield_10067.accountId as List<Map>

def resp = post("/rest/api/2/issue/${issueKey}/notify")
.header("Content-Type", "application/json")
.body([
subject: "test"
textBody: "body",
htmlBody: "Hello",
to: [
users: [[
accountId: approvers,
active: true
]]
]
]).asString()


The code runs fine, but the notification is not sent because 'there are no recipients'. I know i'm doing something wrong with how I get the multiple users and/or how I pass them under the 'to:' part of the code, but I'm out of ideas and completely stuck at this part!

I have also tried to get the value for def approvers as a string, using

def approvers = result.body.fields.customfield_10067.accountId as String[ ]

but I still get the same error. 

I'll appreciate any help on this matter! Thanks!

1 answer

0 votes
kspeight October 3, 2024

Hi   Did you ever get an answer to this problem?

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
TAGS
AUG Leaders

Atlassian Community Events