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 Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

730 views 5 16
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot