Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Custom field condition with Scriptrunner cloud

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?

2 answers

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

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

122 views 1 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you