I'm trying to create a script to run as as post-function and I'm a bit fuzzy on the Jira Cloud REST API. Is there something that exists in the API that allows me to get the value of an issue's custom field?
I know the custom field ID, and Scriptrunner has as its context, the issue ID (I believe). I just need to find how to extract the value for specific custom fields.
Thanks in advance!
Try the below code to get the field value
def key = issue.key
def field = issue.fields
def cfINeed = "customfield_12853"
// hold field value
def my_value
def result = get("/rest/api/2/issue/${key}")
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status < 300) {
logger.info("Success getting fields")
// field value
my_value = field[cfINeed]
} else {
logger.info("Error getting fields")
}
Hi Robert,
I can confirm that we have examples of how to extract values from different types of fields in the documentation page located here and you can run these examples on the Script Console page in order to see how to extract values from different type of fields.
You will be able to use these examples as a reference guide in order to help you to create the script that you require.
As a tip for the future, I can confirm the best way to see what structure a field uses is to set a value in the field on a test issue and then to run the Get Issue Fields example script on the Script Console as this will return the JSON structure for the issue and show how the data is stored for the field and you can use this to help see what structure you must specify to extract the value from a field on an issue.
I hope this information helps.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think I'm close. I looked at https://community.atlassian.com/t5/Jira-questions/ScriptRunner-Cloud-Getting-fields-for-issue-takes-too-long/qaq-p/1597099 and it showed me how to specify the fields I want using queryString.
The static analyzer doesn't like the "value" in each statement for the fields. Anyone have any experience with the call?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.