Using Scriptrunner, I'm looking to add a validator on the creation of a ticket that specifies if a certain component field is selected, then another field cannot be null or 'None'.
I was advised with the following:
issue.getComponents()*.name == 'ComponentValueA' && cfValues['Field A']?.value != null
If I understand the above statement, it's saying that components is equal to "ComponentValueA" and the custom field "Field A" is not null.
The script is then supposed to check if the above statement is true and only error if it's false. Unfortunately, it seems to always error.
I've tried to switch the null to "None" as that's the default value of "Field A" and attempted to treat components as a custom field but bother gave the incorrect results.
It's really not wise to have a literal default value of "None" for select fields. It becomes confusing with the system's apparent default of "None" which means "Null" in db parlance.
If you can search in JQL with:
"Field A" is empty
then you do not have a literal default value of "none". In which case, your original code of != null is appropriate.
Where I see you may get a problem is with issue.component*.name == "ComponentValueA"
That is because the use of * implies that you will return an array.
Aso, if you want to return true when component is something else,
Try this instead:
!('ComponentValueA' in issue.components*.name && cfValues['Field A']?.value == null)
This means, return false when the component is ComponentValueA and Field A is Empty.
So if the component is something else, it will return true.
If component is Value A and Field A is not Empty, it will return true
Hello Peter,
Understood regarding the null portion. Checked the configuration and found that it was a system value and not one that was created by us as I originally thought. Apologies for the confusion there.
Regarding the query you gave, it worked flawlessly. Exactly what I needed. I appreciate the extra time you took to give a breakdown of what it does as a whole. Makes the next items I have to accomplish that much clearer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad I could help.
Don't forget to make the question as answered to help others find this solution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter,
I have problem reading selected component drop down value from components dropdown list. I am using below code to read selected component value and verify the condition, Is there anything wrong with this ?
def issue = ComponentAccessor.getIssueManager().getIssueObject("Job")
if('Technology' in issue.components*.name )
{
//...
}
else
{
//...
}
-Prakash
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Krishna , where are you using this code?
"Job" is probably not a valid issue key. You need to have the full key for the current issue. Typically something like "JOB-123"
Look in your script context (the (i) icon below the script editor field. This will show you what variables are already defined for you and issue may already be there.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What type of custom field is "Field A"? A select list?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.