I'd like to set a condition for a fast-track script based on the value of a custom field. I used to have this working in Scriptrunner (Server) but cannot find an example of how to work it using Scriptrunner (Cloud).
My successful old implementation was:
cfValues['Change Category']?.value == 'Fast Track'
All research done so far indicates I need to hard code the custom field ID to be something like (?!):
issueInput.fields.customfield_10107 == [value: '{{Fast Track}}'] as Map
where 10107 is the custom field ID. Which is not ideal as I'd like to refer to the name instead.
Any ideas?
I created this script and used it as condition in post function
//This script is for Scriptrunner Jira Cloud to get custom field value of current issue as condition in postfunction
package com.adaptavist.sr.cloud.samples.events
//define custom field ID from the field where you want to get the value of
def customFieldName = 'customfield_10046'
//create API request to get custom field value
def result = get("/rest/api/2/issue/${issue.key}?fields=${customFieldName}")
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200) {
result.body.fields[customFieldName].value.toString() == "YOUR_CONDITION"
//if you need to check if the field value machtes YOUR_CONDITION and a assingee is set
//result.body.fields[customFieldName].value.toString() == "YOUR_CONDITION" && issue.fields.assignee != null
} else {
return "Error retrieving issue ${result}"
}
Hi!
Thanks for sharing your script! I tried it and it works, despite getting a warning "[Static type checking] - No such property: value for class: java.lang.Object @ line 12, column 5." for
result.body.fields[customFieldName].value.toString() == "YOUR_CONDITION"
Did you encounter this? How can this be rectified?
Regards,
Marianne
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tim,
Thank you for your question.
I can confirm that by default ScriptRunner for Jira Cloud will require you to specify setting the field by its ID due to the fact the Rest API in Jira cloud is required to specify fields by their ID's and the name cannot be used as Jira Cloud does not have a Java API like the server version does.
You can see more details on the differences between the cloud and server versions of the plugin in the documentation page here.
I can confirm that if you wanted to dynamically look up the ID of the field base on its name then you can do this by making a call to the field rest API to return the field based on its name.
I can confirm that we have an example of how to do this inside of the documentation page here where the customField rest call returns the field based on its name so that the field can be specified by its ID. You will be able to use this example as a reference to show how you can look up fields based on their name.
If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.
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.