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

1 vote
Accepted answer

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 Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,126 views 0 8
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