Scriptrunner listener variable [ issue ] not declared

Trying to populate a date customfield from another date customfield on CustomFieldUpdated Event. Copied some of this code from other posts. I am getting variable [ issue ] not declared error.

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.issue.field.CustomFieldUpdatedEvent
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager

//def issue = event.issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

issue.setCustomFieldValue(
customFieldManager.getCustomFieldObjectByName("Audit Original Testing Due Date")
, customFieldManager.getCustomFieldObjectByName("Audit Testing Due Date"))

2 answers

0 vote
Mikael Sandberg Community Champion Dec 21, 2017

Replace //def issue = event.issue with 

def issue = event.issue as Issue

Sorry, forgot to mention I tried that earlier. The error I get with "def issue = event.issue as Issue" is "Cannot find matching method"method error.png

Mikael Sandberg Community Champion Dec 21, 2017

You cannot use setCustomFieldValue when running it as a listener. In a listener you need to use updateValue, like this:

textCf2.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(textCf2), myval),changeHolder)

Tried this earlier. No errors on the inline script editor, but the other field also does not get updated. Code below:

 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager

def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tgtField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "Audit Original Testing Due Date"}
def changeHolder = new DefaultIssueChangeHolder()
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), customFieldManager.getCustomFieldObjectByName("Audit Testing Due Date")),changeHolder)

 

There are no errors in the log

Mikael Sandberg Community Champion Dec 21, 2017

Have you tried getting the target field by using 

def tgtField = customFieldManager.getCustomFieldObjectByName("Audit Original Testing Due Date")

Thanks for the suggestion. Just tried this. No errors in log, but the code has not been called by the listener for CustomFieldUpdated Event

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

179 views 0 4
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