The variable [invalidInputException] is undeclared

I have a scriptrunner script, and all seems well until the last line:

import com.atlassian.jira.issue.Issue;
import com.opensymphony.workflow.InvalidInputException;
import org.apache.log4j.Category;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.component.ComponentAccessor;

def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def cf1 = customFieldManager.getCustomFieldObjectsByName("New Hire Account provisioning");
def nhap = cf1.iterator().next();
def nhapvalue = issue.getCustomFieldValue(nhap);

log.setLevel(org.apache.log4j.Level.DEBUG);
log.debug("NHAp: ${nhapvalue}");

if (nhapvalue == "Egencia")
{
invalidInputException = new InvalidInputException("Don't forget to provide the full legal name.")
}

----------------------

I get the message "[Static type checking] - The variable [invalidInputException] is undeclared." I've used this exact structure in another script, and it works flawlessly; I'm baffled as to why it isn't working here. Any ideas?

2 answers

0 vote
Steven Behnke Community Champion Nov 08, 2017

Please indicate where both of the scripts are located. It's likely that one of the locations has InvalidInputException already within scope, whereas the location you're trying to use it in now does NOT have it in scope.

The other script is in a post-function on a Resolve transition, whereas this one is in a post-function on a Create. So yes, it could be that there's something already in the other workflow that allows it to work. So how do I bring this one in scope?

Steven Behnke Community Champion Nov 09, 2017

Perhaps just trying defining the variable? 

def invalidInputException
if(name='aCoolName'){
invalidInputException = new InvalidInputException("Please provide the full legal name")
}

Hi Maya. 

If it is a static type error, does it mean that you haven't actually run it yet? Do you mean that you are getting one of the small red crosses in your code?

If so, that could mean that it isn't broken at all. Could you save the script and run it?

Cheers

DYelamos

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 Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

206 views 2 11
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