I have a custom field with multiselect options. I want to as a transition comparing the selected value of the custom field with a given String.
i did the following:
from com.atlassian.jira.component import ComponentAccessor;
from com.atlassian.jira.issue.fields import CustomField;
def value = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12032"));
if (value != null && "Business Trips".equals(value[0].getName()) {
return "This is not a valid vendor!";
}
But the transition does not work on Create. Any ideas?
Hi Olivera,
It appears that you are trying to write a scripted validator, yes? Here's what you need to fix it:
import com.atlassian.jira.component import ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
def value = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12032.toLong()));
if (value && value[0].getValue().equals("Business Trips")) {
throw new InvalidInputException("This is not a valid vendor!")
}
return true
Please keep in mind, that since your custom field is a multi-select type, it's value is a collection of options. The code above always checks only the first selected option.
It still does not work. Do you have any resources with code so I can learn?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you please give me more info? What does it say? Does it let you transition your issue? What is the value of your custom field when you are trying to transition your issue?
Cheers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When testing the exception message does not show/ It gives an error:
"We can't create this issue for you right now, it could be due to unsupported content you've entered into one or more of the issue fields. If this situation persists, contact your administrator as they'll be able to access more specific information in the log file."
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you specify what type of validator is? Is it a Jython script? A custom one?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To narrow down the list of possible reasons for this behaviour, if you remove the validator for your 'Create' tansition, does it allow you to create issues after that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes. It seems that the validator poses the problem. I put the code into a Jython script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
oh, Jython. I thought you had Scriptrunner. Unfortunately i'm not familliar with Jython, but looking at your original code I see at least one mistake. In your 'if' statement change 'getName()' method to 'getValue()' and see if that helps. Or if you have Scriptrunner, use that instead and use my code for it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have Scriptrunner and when trying to add your code it gives an error at line:
f (value && value[0].getValue().equals("Business Trips"))
value[0] is not allowed.
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.