Change custom field from groovy postfunction


My environmaent is JIRA v6.4.7 and ScriptRunner v3.1.4

This code of postfunction dosn't change custom field's value.

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder

import org.apache.log4j.Category
def Category log = Category.getInstance("set-KAM.groovy")

Issue myIssue = issue

// getting src value
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfClient = customFieldManager.getCustomFieldObject("customfield_12700")
def cfClientValue = myIssue.getCustomFieldValue(cfClient)

def projectManager = ComponentAccessor.getProjectManager()
def projectObject = projectManager.getProjectObjByName(
def projectLeadName = projectObject.getProjectLead().getDisplayName() // String

log.debug("XXX ClientName: " +
log.debug("XXX Lead:   " + projectLeadName)

// updating tgt value
//def cfKAM = customFieldManager.getCustomFieldObject("customfield_21803") //tesfield, single raw
def cfKAM = customFieldManager.getCustomFieldObjects(myIssue).find { == "KAM"} //tesfield, single raw
def changeHolder = new DefaultIssueChangeHolder();

log.debug("XXX KAM before: " + myIssue.getCustomFieldValue(cfKAM)) // null
cfKAM.updateValue(null, myIssue, new ModifiedValue(myIssue.getCustomFieldValue(cfKAM), projectLeadName), changeHolder)
log.debug("XXX KAM after : " + myIssue.getCustomFieldValue(cfKAM)) // null :-(

Could anybody provide working method to update custom field?

Thank you!

2 answers

1 accepted

1 vote
Tuncay Senturk Community Champion Feb 17, 2016

Did you try below?

myIssue.setCustomFieldValue(cfKAM, value)

Exactly! It's Working!

Thank you, @Tuncay Senturk [Snapbytes]!

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 May 30, 2018 in Marketplace Apps

Three tips for boosting your board's efficiency with Story Maps

Trello is one of the most effective tools for driving your sprints. It's customizable for every Agile team and product owners and Scrum masters (SM) love it. However, Agile teams often struggle with:...

849 views 2 9
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