Hi community!
I have field "Field_1" and "Field_2". I want to during the selection Field_1 and value "BR" could choose only K3 value in Field_2. If the values are selected incorrectly then display an error.
I set script validator in create issue.
My code:
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def field_1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("cf1")
def field_2 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("cf2")
def field_1_value = issue.getCustomFieldValue(field_1)
def field_2_value = issue.getCustomFieldValue(field_2)
if (field_1_value == "BR" && field_2_value != "К3") {
throw new InvalidInputException("You must pick only K3 value")
}
This script work but the log is empty and condition not run.
I need to get an error in case of a wrong choice.
What i do wrong?
Best Regards,
Alexander
Hi @Alexander,
May I ask if your custom field/s are Select type ones? If so, the value you get is not a String, but a LazyLoadedOption, so when you compare them with == result is false.
Instead, try to get the Option value using method getValue(), ie:
def field_1_value = issue.getCustomFieldValue(field_1).getValue()
Btw, I would suggest to use assert to confirm and get details about the operation you are executing.
Hope it helps!
Hi @Alexander,
Did you debug by checking out the two custom field values selected from the UI, in your script? You need to make sure that the if condition is triggered which is not happening in your case.
Please make sure that the custom field names are unique and also, typecast as a string such that variable holds the custom field value for comparison. Your debugging should include checking the value for all cases, to make sure that you are capturing the custom field values in the variables defined in your script.
Thanks,
Ravi Varma
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.