Hi, I'm trying to cobble together a validator script to check whether a checkbox field called New Hire Account Provisioning contains the value Egencia, at the same time checking to see if either of two custom fields is empty. If Egencia is checked and either or both of the two custom fields is empty, I want to throw up an error message. I've done this kind of thing before, and patterned this script off of the one that worked, but this one has the message "[Static type checking] - The variable [cfValues] is undeclared" on my if statement. Obviously cfValues isn't a variable, and I can't see why I'm getting this message. I'm sure I'm missing something obvious, so if you can see it, please help!
My script:
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject('customfield_15564')
log.error (cField)
def cFieldValue = issue.getCustomFieldValue(cField)
log.error (cFieldValue)
def cField2 = customFieldManager.getCustomFieldObject('customfield_16662')
log.error (cField2)
def cFieldValue2 = issue.getCustomFieldValue(cField2)
log.error (cFieldValue2)
if ((cfValues['New Hire Account provisioning']*.value.contains('Egencia')) && ((cFieldValue == null) || (cFieldValue2 == null)))
{
invalidInputException = new InvalidInputException("Manager Email", "Both Department Number and Manager Email are required when specifying an Egencia account be set up.")
}
Hi Maya,
Probably you should use the other way of getting the custom field value? Refer the link below,
-Praveen
Hi Praveen, thanks for answering! I've modified the script to:
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def fieldConfigSchemeManager = ComponentAccessor.getFieldConfigSchemeManager()
def cf = customFieldManager.getCustomFieldObjectByName("New Hire Account provisioning")
def config = fieldConfigSchemeManager.getRelevantConfig(issue, cf)
def allOptions = optionsManager.getOptions(config)
def checkboxFieldValues = cf.getValue(issue)
def cField = customFieldManager.getCustomFieldObject('customfield_15564')
def cFieldValue = issue.getCustomFieldValue(cField)
def cField2 = customFieldManager.getCustomFieldObject('customfield_16662')
def cFieldValue2 = issue.getCustomFieldValue(cField2)
checkboxFieldValues.each { optionValue ->
if (optionValue == 'Egencia')
log.error('Egencia found')
}
-----------
It all passes the syntax test, and I've confirmed that optionValue does actually equal Egencia when that option is checked, with a logging statement, but the if statement never evaluates to true. Any idea why?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, I figured out the if statement, it needed to be cast to a string. So that part is now:
checkboxFieldValues.each { optionValue ->
if ((optionValue.toString() == "Egencia") && ((cFieldValue == null) || (cFieldValue2 == null)))
invalidInputException = new InvalidInputException("Manager Email", "Both Department Number and Manager Email are required when specifying an Egencia account be set up.")
}
But now I'm back to my original question - it thinks invalidInputException is a variable. What gives?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Maya,
Can you try the below code, check the below links,
InvalidInputException e= new InvalidInputException() e.addError("error message") throw e;
https://community.atlassian.com/t5/Jira-questions/The-simplest-Groovy/qaq-p/350307
-Praveen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Now it says the variable e is undeclared. I don't see anything in the links where e has to be declared?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Spaces matter in code - "e=" is not the same as "e =". I think Praveen missed a space in the first line of code in the last comment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nic, thanks for that, I added the space between e and = but it is still telling me that e is an undeclared variable on the e.addError("error message") line.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.