Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Change custom field from groovy postfunction

Mayorov Alexander February 17, 2016

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

2 votes
Answer accepted
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 17, 2016

Did you try below?

myIssue.setCustomFieldValue(cfKAM, value)

0 votes
Mayorov Alexander February 17, 2016

Exactly! It's Working!

Thank you, @Tuncay Senturk [Snapbytes]!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events