Hi all,
I am trying to set a custom field value on issue creation via a Scriptrunner post function on a Jira Service Desk Cloud instance.
So far I have tried:
(regionId = the ID of the region custom field)
(nations_json[i]?.region = Value I am trying to set the 'Region' field to)
put("/rest/api/2/issue/${issue.key}")
// .queryString("overrideScreenSecurity", Boolean.TRUE)
.header("Content-Type", "application/json")
.body([
fields[
(regionId): nations_json[i]?.region
]
])
.asString()
log.debug("REGIONFIELD " + customFields.find { it.name == 'Region' })//This returns details about the 'Region' custom field
log.debug("REGIONFIELD " + customFields.find { it.name == 'Region' }?.value) //This returns null
However when I try to return the value stored within the 'Region' custom field, it returns NULL, see log output below:
2020-01-29 13:58:07.001 INFO - Serializing object into 'interface java.util.List'2020-01-29 13:58:07.012 INFO - GET /rest/api/2/field asObject Request Duration: 540ms2020-01-29 13:58:07.344 INFO - Serializing object into 'interface java.util.List'2020-01-29 13:58:07.350 INFO - GET /rest/api/2/field asObject Request Duration: 299ms
2020-01-29 13:58:07.410 DEBUG - REGIONFIELD [id:customfield_10179, key:customfield_10179, name:Region, custom:true, orderable:true, navigable:true, searchable:true, clauseNames:[cf[10179], Region], schema:[type:option, custom:com.atlassian.jira.plugin.system.customfieldtypes:select, customId:10179]]
2020-01-29 13:58:07.412 DEBUG - REGIONFIELD null
2020-01-29 13:58:07.430 INFO - Condition didn't eval to true, exiting
Does anybody know how to correctly set a custom field value?
Hi Rajeev,
Can I please ask you to provide the screenshot of how your Post Function has been configured on the Create Transition of the workflow.
I can confirm that in order to access the values inside a post function on the Create Transition that you must order your post function to be the last one in the list below the post function named Re-index an issue to keep indexes in sync with the database.
The reason for this is that if it is not ordered below this post function then the field values will not be set on the issue so will return null and mean they cannot be used inside of your script.
Regards,
Kristian
Hi Kristian,
I am triggering this script on the pending transition not the create transition. This is so I do not have to create a new issue every time I want to trigger the script (This is for testing purposes and will be changed to create once I know the script works correctly)
This is how the PF is configured:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rajeev,
I notice you are also asking the same question on the community answer at: https://community.atlassian.com/t5/Jira-Service-Desk-questions/How-to-get-and-set-custom-field-values-via-API/qaq-p/1282045?utm_source=atlcomm&utm_medium=email&utm_campaign=immediate_general_reply&utm_content=topic so I will respond to the other community answer in order to keep all responses in one post.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.