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.
Do you have the Scriptrunner add on installed? It has a feature called "Scripted Fields" that can do this.
Hi @inayatulla.shaik
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 keydef issueOne = get("/rest/api/2/issue/${issueKey}").header('Content-Type', 'application/json').asObject(Map).bodydef issueOneFields = issueOne.fields as Mapreturn issueOneFields[customField] ?: 0}def issueKey = "" //Some issue key stringdef customFieldOne = "" // Some custom field stringdef customFieldTwo = "" // Some other custom field stringdef valueOne = getCustomVal(issueKey, customFieldOne)def valueTwo = getCustomVal(issueKey, customFieldTwo)// Now perform some operationdef newVal = valueOne + valueTwo// Perform a comparisonif (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
It looks like you're new here. Sign in or register to get started.