Forums

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

In CLOUD, how to update a User picker single select value in a Listener

Mordechai Cikk
Contributor
June 12, 2018

Hi,

In a CLOUD environment Script Listener I am trying to set the a User Picker (single select) to a specific user. I tried with the user key as well as the Name but I am only clearing out the field.

I was using the syntax for updating a standard custom Single Select field which works fine for that type of field.

 put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
('customfield_10409'): [value: 'Yes']
]
])
.asString()

 

But for the user picker this is apparently not right:

put("/rest/api/2/issue/${issue.key}")
.header("Content-Type", "application/json")
.body([
fields:[
('customfield_16431'): [value: 'martyc']
]
])
.asString()

 

Would greatly appreciate a push in the right direction on this.

Thanks.

1 answer

1 accepted

1 vote
Answer accepted
Kristian Walker _Adaptavist_
Community Champion
June 13, 2018

Hi Mordechai,

I have enclosed a sample script which you can run in the Script Console to update an issue and set a single user picker field.

def issueKey = '<IssueKeyHere>'
def newSummary = 'Updated by a script - Setting User Picker Field'

def result = put('/rest/api/2/issue/' + issueKey)
.header('Content-Type', 'application/json')
.body([
fields:[
summary: newSummary,
// The custom field representing my user picker field
customfield_<FieldIDHere>: [name:"<UsernameHere>" ]
]
])
.asString()
if (result.status == 204) {
return 'Success'
} else {
return "${result.status}: ${result.body}"
}

This should show you the syntax that you need to set a user picker and allow you to update your script to achieve this.

If this answer has solved your issue can you please accept it in order to mark this answer as correct for users who are searching for a similar issue.

Regards,

Kristian

Mordechai Cikk
Contributor
June 13, 2018

Thanks Kristian!

I was using the incorrect [value"<UsernameHere>" ] instead of the correct 

[name:"<UsernameHere>" ]

  Thanks or the push in the right direction.

David Chell
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 23, 2019

When I try this I get the following error:

Field 'customfield_15500' cannot be set. It is not on the appropriate screen, or unknown.

 The custom field is definitely on the screen.

Kristian Walker _Adaptavist_
Community Champion
July 24, 2019

Hi David,

I can confirm that the script above is no longer valid on Jira Cloud since Atlassian released the GDPR changes this year which meaans that users can no longer be set via their username and instead must be set using their accountID

I can confirm that we have created a page in our documentation located here which shows how to set a user using their accountId since the GDPR updates and you should follow the approach in this page in order to show to modify the script above to specify the user using an accountId

I can confirm that  the simplest way to find out the account id for a user will be to navigate to the People page inside of your Jira cloud instance which you can view by navigating to the URL of <JiraCloudBaseURL>/people/search.

Once on this page you can search for the name of the user that you need to find the accountID for and you will find the account ID in the URL when you load the people page for the user after the URL of <JiraCloudBaseURL>/people/<AccountIDWillBeHere> where the value after the people/ section of the URL is the  accountID.

Regards,

Kristian

Adam February 24, 2020

Kristian_Walker is right, you will no longer be able to update fields based on name.  Account ID must be used.  This change broke many of my scripts.

 

The new and easiest syntax to use is:

 

{"fields":{"customfield_10117":{"accountId":"5b11682473c2"}}}

OR

{
"fields": {
"customfield_10117": {
"accountId": "5b11682473c23f253a5f7a37"
}
}
}


If you are looking to do this programmatically, you will need to perform a get based on name.  I suggest creating a function (that is what I did) for grabbing account ID based on name.

Here is the rest URL you can use:

"https://DOMAIN.atlassian.net/rest/api/latest/user/search?startAt=0&maxResults=1000&username=USERNAMEHERE"

 Just replace the markers: DOMAIN and USERNAMEHERE with your domain and username you are searching for, it should return an object with the attribute "accountId" that you want.

Hope this helps

Suggest an answer

Log in or Sign up to answer