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

How to set field value?

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 24, 2018

Hi Mariana,

We have example scripts on our new website that detail how to set custom field values. Take a look here: https://library.adaptavist.com/entity/update-the-value-of-a-custom-field-in-jira

Have you actually tried running the script? The static type checker may tell you there's an error, but it'll probably work anyway.

Thanks,

Josh

TAGS
AUG Leaders

Atlassian Community Events