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

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

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);

 

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!!!

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

53 views 0 5
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you