Forums

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

Jira Scriptrunner Cloud: How to set User Picker (Single User) custom field in scriptrunner cloud

Mark Sayo December 1, 2023

Hi,

We are trying to set a custom field User Picker (Single User) using scriptrunner.

We tried email or accounID but still the Reporting Manager field User Picker (Single User) is not updating. 

This is what I noticed, when there is a user already set in the Reporting Manager field, the value will be blank when we run the script.


def customfieldID = 'customfield_10202' // Reporting Manager
//def newFieldValue = 'mark@email.com'
def newFieldValue = '123456%3A6f714ab0-e00b-000e-0000-0000c7d000000' //accountid 
def issueKey = 'FAC-152'

def result = put("/rest/api/3/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields: [
customfieldID: [
id: newFieldValue
]
]
//]).asObject(Map)
]).asString()
if (result.status == 204) {
return 'Success'
} else {
return "${result.status}: ${result.body}"
}

1 answer

1 accepted

0 votes
Answer accepted
Bobby Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 1, 2023

Hi @Mark Sayo , 

Your script to update a user pick field is almost 100% correct, just need to change 'id' to 'accountId'. 

So, could you try the following and let me know how you get on?

 

def updateResult = put("/rest/api/3/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields:[
customfieldID: [
accountId: newFieldValue
]
]
]).asString()



Kind regards, 

Bobby

Mark Sayo December 3, 2023

Hi Bobby,

Now I am getting error 400

PUT /rest/api/2/issue/FAC-152 asString Request Duration: 667ms
PUT request to /rest/api/2/issue/FAC-152 returned an error code: status: 400 - Bad Request
body: {"errorMessages":[],"errors":{"customfieldID":"Field 'customfieldID' cannot be set. It is not on the appropriate screen, or unknown."}}
Serializing object into 'interface java.util.Map'
Please use the ScriptRunner user to complete this task not the Initiating User.
See https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-editIssue for more information.
If you are using the ScriptRunner user then check the Field Configuration

 

Already check Screen, and the Scriptrunner user.

Still error persist.

Bobby Bailey
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 4, 2023

Ahh, apologies @Mark Sayo , I forgot that the value "customfieldID" in the API call needs to be in brackets, so rather than:

         customfieldID: [
accountId: newFieldValue
]


It should be:

         (customfieldID): [
accountId: newFieldValue
]



Sorry for the confusion! Could you try that and let me know the results?

Kind regards, 

Bobby

Like Mark Sayo likes this
Mark Sayo December 5, 2023

HI Bobby,

 

Cool! This is now working.
Thanks!

Like Bobby Bailey likes this

Suggest an answer

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

Atlassian Community Events