Couldn't modify a Custom field value, via ScriptRunner

Hi,

I'm using ScriptRunner and trying to find a way to modify a value of certain Custom field.

The code below runs just fine, values which were printed to log, are the correct values..

But it doesn't post to DB the change that I made to the Custom field.

I'm using one of the 2 recommended methods to modify values - in my case:

'updateValue':

 

package com.onresolve.jira.groovy.test.scriptfields.scripts

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import groovy.xml.MarkupBuilder
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import org.apache.log4j.Logger
import org.apache.log4j.Level

 

//Parameters

//Get an Issue object
def issue = event.issue as Issue;

//Get a Log object
def log = Logger.getLogger("com.acme.CreateSubtask");

String issueType = "Default_Type";

//Get the type of this issue (Bug, Story, etc.)
issueType = issue.getIssueType().getName();
log.setLevel(Level.DEBUG);


if (issueType.equals("Bug"))
{
log.debug ("IssueType is: Bug");


//**************************************
//Set a field's value
//**************************************

//Get a CustomFieldManager object
def customFieldManager = ComponentAccessor.getCustomFieldManager();

//Get a specific field - using the field Name label
def tgtField = customFieldManager.getCustomFieldObjectByName("Scrum Team");

//
def selectedFieldName = tgtField.getFieldName();
log.debug ("Selected Field Name: " + selectedFieldName);

//Get the current value of a Selected Custom field
def selectedFieldValue = issue.getCustomFieldValue(tgtField)
log.debug ("Selected Field Value: " + selectedFieldValue);


//Define a DefaultIssueChangeHolder
def changeHolder = new DefaultIssueChangeHolder()

//Modify the field's value
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), "DEV"),changeHolder);


}

1 answer

Update:

Issue was with the field type.

Tried to post String value into a 'Select List (single choice)' field type.

It should be defined first, though that list of mine includes String values...

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,326 views 14 20
Join discussion

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