Hi, I have just started my journey with JIRA. I have created two custom fields. So my task is that I suppose to display one field based on other field value. Can some one help me out groovy script in this regard.
I have an idea of a Script that can be modified to do what you ask, but the basics are there.
def getCustomVal(issueKey, customField) {
// Fetch the issue object from the key
def issueOne = get("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.asObject(Map).body
def issueOneFields = issueOne.fields as Map
return issueOneFields[customField] ?: 0
}
def issueKey = "" //Some issue key string
def customFieldOne = "" // Some custom field string
def customFieldTwo = "" // Some other custom field string
def valueOne = getCustomVal(issueKey, customFieldOne)
def valueTwo = getCustomVal(issueKey, customFieldTwo)
// Now perform some operation
def newVal = valueOne + valueTwo
// Perform a comparison
if (valueOne > valueTwo) {
return valueOne
}
else {
return valueTwo
}
Once you get the custom field values, and do whatever operation you want with them, there are other options as well.
For example, you could modify ScriptRunner's example script for creating a task to create a new task with the result from above.
For reference, that example code is this:
def projectKey = 'TP'
def taskType = get('/rest/api/2/issuetype').asObject(List).body.find { it['name'] == 'Task' }['id']
post('/rest/api/2/issue')
.header('Content-Type', 'application/json')
.body(
[
fields: [
summary : 'Task Summary',
description: "Don't forget to do this!.",
project : [
key: projectKey
],
issuetype : [
id: taskType
]
]
])
.asString().body
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you have the Scriptrunner add on installed? It has a feature called "Scripted Fields" that can do this.
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.