Change custom field from groovy postfunction

Hello!

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")
log.setLevel(org.apache.log4j.Level.DEBUG)

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(cfClientValue.name)
def projectLeadName = projectObject.getProjectLead().getDisplayName() // String

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

// updating tgt value
//def cfKAM = customFieldManager.getCustomFieldObject("customfield_21803") //tesfield, single raw
def cfKAM = customFieldManager.getCustomFieldObjects(myIssue).find {it.name == "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 :-(
log.debug("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

Could anybody provide working method to update custom field?

Thank you!

2 answers

1 accepted

This widget could not be displayed.

Did you try below?

myIssue.setCustomFieldValue(cfKAM, value)

This widget could not be displayed.

Exactly! It's Working!

Thank you, @Tuncay Senturk [Snapbytes]!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

513 views 3 18
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