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
Answer accepted

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
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


254 views 0 6
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