Trying to make a field required when a prior field is populated. We dont use the behaviours plug-in. The first field is a multi-select and I have a saved issue with 1 of the 3 values selected. The field is customfield_14523, the value is 15300 and the field label is Production.
I'm trying this command using Workflow Validator Built-in script
cfValues['customfield_14523']*.value.contains("15300") && cfValues["customfield_14807"]*.value == ("")
After failing, I thought I'd test the first half of the script with Script Runner and the saved issue.
Go into Script Runner, enter the key of the issue, give it this command:
false, get this...javax.script.ScriptException: java.lang.NullPointerException: Cannot invoke method contains() on null object...
The multi-select object isn't null, it has a value...15300, viewable in firebug with a label of "Production"
I also tried ? instead of *...Production instead of "15300", double quotes, single quotes...fail.
It should be cfValues['Production']
Give the cf name, not the ID.
> You assume that every entry in collection cfValues['customfield_14523'] has property 'value'
I think this is a reasonable assumption if you know it's a multiselect, but yeah, it's good to print out the class type.
You assume that every entry in collection cfValues['customfield_14523'] has property 'value' which seems to be false assumption. cfValues['key'] gives you some probably some kind of single value, and best solution to find out what is this value would be to place such a statement in validator:
It should give you class name of object that lays inside this custom field. Then post it here or consult apropriate javadoc to find out your way.
Here's the html from firebug, I wasn't clear about labels previously, sorry.
So based on the html below, would the second statement be correct in your opinion?
Sidenote: Our script runner is having issues, it doesn't generate any samples when i click the sample links so I have create sample grails code while adding a validator in a workflow, then go back to the test validator, paste, run it in the tester. I have another person looking at this as well, we noticed it's randomly returning true and false so we're not sure our install is correct either. I'll try the log statement in a few.
The html is not relevant here (except to understand your options) ... the validation happens server-side.
The correct statement is the second one, presuming Production is the value of the option. From your earlier comments I assumed 15300 was the display value.
If you want to look it up by ID then something like:
From the html it looks like "Production" contains leading and trailing spaces? Unless that's added in by jira. Which would explain why it's not working for you.
To conclude finally, but I'm still confused...
this below is what REALLY works in a workflow which differs from what works in the Script Runner Validator.
cfValues["Required PROD Date"] == '';
If field Capsil Platforms has "Production" selected and the Required Prod Date is null, prompt the user to enter the Required Prod Date.
When I tested the second half in the Script runner tester on an existing issue using two single quotes, it returned false. Such as:
cfValues["Required PROD Date"] == ''
If I set it to use null, it returned true.
cfValues["Required PROD Date"] == null
But when I put the code with null in a workflow as a create transition, it doesn't fire...so we played around and had to use two single quotes instead of null.
The tester uses an existing issue, a create is different...so during entry a field that hasn't been entered is not necessary set to null until it is saved?
In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to have–in order to produce a reliable long-term roadmap. We're tur...
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!
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