Need to update the value of a JIRA custom field from NULL to the value specified in the script using groovy

Nishant Kansal March 30, 2016

Please tell me what is wrong with this script? It is returning NULL.

Requirement: Need to update the value of a custom field from NULL to the value specified in the script.

----------------------------------------------------------------------------------------------------------

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;

def fieldid = 14601L //field id; currently having null value
def dbValue = "8.0.8" //New value to be assigned to the custom field

def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("TIK-3039"); //issue in JIRA
MutableIssue myIssue = issue;

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(fieldid); //Identification of Custom Field Object

myIssue.setCustomFieldValue(customField,dbValue); //updating the value from "Null" to the value declared above "dbValue"

----------------------------------------------------------------------------------------------------------

Best regards,

Nishant

2 answers

1 accepted

0 votes
Answer accepted
Aleks Yenin (Polontech)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 30, 2016

Hi Nishant,

Try this one

 import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
Long fieldid = 14601L //field id; currently having null value
def dbValue = "8.0.8" //New value to be assigned to the custom field
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("TIK-3039"); //issue in JIRA
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(fieldid); //Identification of Custom Field Object
issue.setCustomFieldValue(customField,dbValue); //updating the value from "Null" to the value declared above "dbValue"
return (String) issue.getCustomFieldValue(customField);

 

Nishant Kansal March 30, 2016

Thanks Aleks for your inputs. Just a minute back only, I also did the same and it worked perfectly...smile...I was missing the return statement!!!

0 votes
Nishant Kansal March 31, 2016

Hi,

I have 3 groovy scripts- A, B and C 

1. "A" calculates certain values and puts them into an array
2. "B" takes those values as inputs from A and connect to an external database and returns a value
3. "C" takes that return value from "B"  

As of now, I have hard coded the values in each of the script to develop and test. However, in real time, I want them to be one script with the above dependency in place. 

How I can combing them under one script? This script then will be added as a post function in JIRA.

Please help. 

Thanks, 
Nishant

Suggest an answer

Log in or Sign up to answer