Cannot update Value scripted field

Mariana Morgulis October 24, 2018

Hi,

We need to copy a value from custom field to our text scripted field.

Below is the script that we create, which works properly as post function in workflow, however, has an error in scripted fields of the Script Runner in JIRA.

the error: "Cannot find matching method"  on the bold rows.

Someone know why? and how to fix it?

import org.apache.log4j.Logger
import org.apache.log4j.Category
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.event.type.EventDispatchOption

def Category log = Category.getInstance("com.onresolve.jira.groovy.Condition")
log.setLevel(org.apache.log4j.Level.DEBUG)


def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def newPVP = customFieldManager.getCustomFieldObject('customfield_16680') //PVP - custom field
def newPVPValue = issue.getCustomFieldValue(newPVP) as String
log.info("newPVPValue: " + newPVPValue)


def PVPCommit = customFieldManager.getCustomFieldObject('customfield_16781') //PVP Committed - custom field
def PVPCommitValue = issue.getCustomFieldValue(PVPCommit) as String
log.info("PVPCommitValue: " + PVPCommitValue)


if (PVPCommitValue==null) {
issue.setCustomFieldValue(PVPCommit, newPVPValue)
// issue.updateValue(PVPCommit, newPVPValue)
} else {
issue.setCustomFieldValue(PVPCommit, PVPCommitValue + ", " + newPVPValue)
}

 

1 answer

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 24, 2018

Scripted fields do not contain data directly, and they cannot be "set".

A scripted field works out what data to display, search on and sort by, by using the script associated with it.

I don't think you want a post-function here at all.  You should take this script and add it to the script for the scripted field, then change the bold lines to "return <content I want to see>" instead of "setCustomField".

Chhaya Gadade October 18, 2019

Hi @NI

How to get value of scripted field in script.Do you have any idea?

def dev_estimate = customFieldManager.getCustomFieldObject("customfield_12345");
log.warn("dev_estimate=="+dev_estimate);

def categoryFieldValue = issue.getCustomFieldValue(dev_estimate);
log.warn("dev_estimate value=="+categoryFieldValue);

 

Above code is not giving me value of scripted field i.e.dev_estimate is my scripted field

Suggest an answer

Log in or Sign up to answer