I know there is a known issue for this, so I was wondering if anyone knows any workaround solution for making the 2nd drop down required. Is there any plugin or a way we can validate and enforce this rule?
Thanks in advance
Update 22 Sep 2015: There are Simple Scripted Validator examples with cascading selects, here: https://scriptrunner.adaptavist.com/4.1.3-SNAPSHOT/jira/recipes/workflow/validators/simple-scripted-validators.html#_validating_cascading_selects
The problem with that code is that it retrieves the issue from the database, and doesn't reflect what's currently in the form. The behaviours plugin is about interacting with the user while the form is being edited, which means you need to get the form value by calling getFormField(getFieldByName(...)).getValue() or similar.
But, I don't think the behaviours plugin supports cascading selects...
Here's another solution if you have the script runner plugin. Add a validator to your workflow of type "Script Validator", then choose the built-in script "Simple Scripted Validator", then enter this for the condition,
cfValues["CascadingSelect"]?.getKeysAndValues()?.size() == 2
and put your error message in too.
Update: As of some jira version, (5.2 ?) the field value seems to be stored as a map, so to check both parts of a cascading select are filled use:
cfValues.get("CascadingSelect")?.keySet()?.size() == 2
Yea, I tried so many ways with behaviours and it doesnt seems to work on cascading select (perhaps an improvement point?)
I am not too sure about the script validator as I want the error to appear whne the user submit the form and not when it proceed to the next step...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have mistaken your suggestion before. I didnt know you can add validation on create within workflow (never have to do it so far). Your suggestion works!!!! Thank you! I reallly wish JRA-10302 is fixed b/c this is definitely a bug :T
Thanks again
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just realize it only works for create but if you edit, it doesnt check that step. Since edit is not really part of the workflow (or is it?), how can you add similar validation for the cascade select?
Thanks again
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah, that's problematic. Not sure if there is an outstanding request for this in the behaviours plugin.
Note also somehow I missed two crucial question marks in my line above - without these you will get a NullPointerException if the first part of the cascading select is empty.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jaimie,
Having problems getting the following cascade selection field (Service Affected) validation to work in a workflow:
cfValues["Service Affected"]?.getKeysAndValues()?.size() == 2
ERROR bryank 596x729001x1 osaq3c 66.54.212.165,10.110.199.61 /secure/QuickCreateIssue.jspa [groovy.canned.utils.ConditionUtils] javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.util.HashMap.getKeysAndValues() is applicable for argument types: () values: []
I am running Jira 5.26, Script Runner 2.1.3
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi bryan, jira api seems to have changed... I updated my answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jamie -- you rock! that did the trick. Thank you very much!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All,
I want to validate the parent option of a cascading select list rejected the None option. I set the validator as follows:
cfValues['Cascading Field'].getValue() != ""
That does not work. This field is required via the Field Configuration. What's wrong with the validator?
Many thanks
Marco
JIRA v5.2.4
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie, I tried your both solutions but didnt work for me: got errors like this: Hi , I also tried both the script given but got error in logs onUtils] Condition failed on issue: ARQ-8720, built-in script:com.onresolve.scriptrunner.canned.jira.workflow.validators.SimpleScriptedValidator groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.keySet() is applicable for argument types: () values: [] Possible solutions: toSet(), toSet(), set(int, java.lang.Object), set(int, java.lang.Object), get(int), get(int) at Script16.run(Script16.groovy:1) 2015-09-23 14:11:38,397 ajp-bio-8009-exec-33 ERROR avdhesh.chauhan 851x39158x1 8btozy 10.129.15.65 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] Script follows: cfValues.get("Query Type")?.keySet()?.size() == 2 Please help. Thanks Avdhesh
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.
It can't be a cascading select then. Are you sure it's a standard cascading select and not one provided by a plugin that has more than two levels? A cascading select returns a Map<String, Option>.
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.
Hi Jaimie, should this work for multi select cascading list ( 4 lists) too? Its working fine for cascading list with 2 lists but not with 4, any reason? I have just replaced the 2 with 4 in this case. BTW the multi select cascading list is a trial version of the add on installed in my JIRA.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Multi select cascading list is not supported by the behaviours plugin, but you should be able to use it fine with simple scripted validator or any script validator function. I'm not really sure what you're saying is not working, probably best to open a new question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried this code in a scripted validator:
cfValues. get ( "CascadingSelect" )?.keySet()?. size () == 2 |
It works well when creating an issue the normal way, but Service Desk throws an error "This issue can't be created through Service Desk" every time and won't let me create tickets regardless of the values in the cascading field.
Is there a workaround?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What version of JSD? It used to be completely broken with respect to workflow validators, eg https://jira.atlassian.com/browse/JSD-221.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I use this Script
"cfValues['Department and Service']?.values()*.value.size() == 2"
and meet this Error. Please hepl
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Using Jira 7.10 I have also been getting Static Type errors, but when using
"cfValues.get['your_ cascading_field_name']?.key.set()?.size() == 2" as a simple scripted validator, as per instructions at:
I found this returned the following error -
[Static Type Checking] - Cannot find matching java.lang.Object#keyset(). Please check if the declared type is correct and if the method exists. Possible solutions: getAt(java.lang.String) @ line 1, column 1.
I raised a ticket with Adaptavist and was told "Static type checking errors can sometimes be ignored, and this is one of those cases. The code should still work fine, even though an error is shown. That being said, you can try using this code instead and seeing if that gets rid of the error:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def issue = issue as MutableIssue
def cascadingSelect = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)?.findByName("CascadingSelect")
def values = issue.getCustomFieldValue(cascadingSelect) as HashMap
// Will return true if both the parent and child options in the Cascading Select have a value
values?.keySet()?.size() == 2
I haven't tried ignoring the static type error, but have tried the code provided and it worked a treat. Hopefully may help you or someone else facing the same problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I could achieve this using Validators for Create option in workflow. I used groovy script. This is what I have used:-
issue.get("customfield_12504")?.get("1")?.optionId
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import java.util.Collection;
(cfValues["Discovery Stage"] as HashMap)?.keySet()?.size() == 2
Works, but if a first value has no second value related to it - you won't be able to select it
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all, can someone help me with this one, similar to the original question. I have a cascading field, parent part and child part. I want the child part to be mandatory if you select a valid value in the parent part. This must be checked in the edit issue mode. How do I do that (I'm not experienced with scriptrunner coding.)? I use Jira Software v7.11. Thanks for the help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi - see my post above from Jan 03 2019.
The only way I have been able to make the child part mandatory is on workflow transitions and not the edit screen. This wasn't too bad for us as we placed on the create transition meaning both had to be completed when creating an issue.
You do this by adding a simple scripted validator on the workflow transition(s). The code is:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
def issue = issue as MutableIssue
def cascadingSelect = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)?.findByName("Name_of_your_CascadingField")
def values = issue.getCustomFieldValue(cascadingSelect) as HashMap
// Will return true if both the parent and child options in the Cascading Select have a value
values?.keySet()?.size() == 2
It does mean it can still be edited but in reality would someone edit to remove the child part? Depending on your exact requirements you could experiment with having the validator on multiple workflow transitions so if someone did remove it would be required again when the issue was moved. You could always remove the cascading field from the edit screen as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi David,
I am also trying to do the same as Sandra but during issue Create.
" I have a cascading field, parent part and child part. I want the child part to be mandatory if you select a valid value in the parent part."
I've tried your simple script code (above) but it does not work.
Your assistance is greatly appreciated!
Jira v8.5.1
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To make second field of cascading custom field mandatory, you need to perform changes in the workflow.
go to the workflow associated with that cascading field, put a field required validator for cascading field in that work flow, and it will start working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have the same problem. My JIRA is in CLOUD, and I have runner script, but I can not include script as validation .. any other ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@monika singh -- as of Jira v7.13 and JSU v2.11, making the field required through a workflow validation only requires that a user populates the parent option of the cascading field instead of both the parent and child
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I traied all values, but dosent work. Some news about this tip??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is a great little tip but I am having trouble getting it to work as expected. When trying to save the issue the error triggers even when both parts of the field are populated. Any ideas why this may be occurring?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just tested this and it worked fine... can you attach a screenshot of the workflow function configuration.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie, I have added validation on create transition for validation of casecade field as required for both drop downs.But is not working.It showing error message that we have added while adding post function.I am missing anything. cfValues.get("CascadingSelect")?.keySet()?.size() == 2
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi , I also tried both the script given but got error in logs onUtils] Condition failed on issue: ARQ-8720, built-in script:com.onresolve.scriptrunner.canned.jira.workflow.validators.SimpleScriptedValidator groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.keySet() is applicable for argument types: () values: [] Possible solutions: toSet(), toSet(), set(int, java.lang.Object), set(int, java.lang.Object), get(int), get(int) at Script16.run(Script16.groovy:1) 2015-09-23 14:11:38,397 ajp-bio-8009-exec-33 ERROR avdhesh.chauhan 851x39158x1 8btozy 10.129.15.65 /secure/CommentAssignIssue.jspa [canned.jira.utils.ConditionUtils] Script follows: cfValues.get("Query Type")?.keySet()?.size() == 2 Please suggest.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Responding to your comment, there is an example of checking the values of cascading select lists here: https://studio.plugins.atlassian.com/browse/GRV-42
So if cfVal.getAllValues()[1] is null you can throw an InvalidInputException.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jamie, thanks for your quick reply, that example is what i was looking for.
I put this code into the behaviour plugin but for some reason even when I pick value for second drop down, it somehow cache the old value and thus error out in an infinite loop (or so it seem)
I thought the error would reevaluate when user press "Update/Create"? Thoughts?
Thanks again for your help :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That code is for the script runner plugin... is that what you meant?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I actually put the code in behaviours plugin -> server side scripts. It compile fine but it doesnt work like i wanted. When I create the issue, it bypass the validation, and when I edit with both values filling in, it just keep erroring out. Here is the code (I think that might be the easiest)
import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.customfields.view.CustomFieldParams import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.ComponentManager import java.util.Collection; ComponentManager componentManager = ComponentManager.getInstance() CustomFieldManager customFieldManager = componentManager.getCustomFieldManager() MutableIssue issue = componentManager.getIssueManager().getIssueObject(formContents["id"] as Long) CustomField cf = customFieldManager.getCustomFieldObjectByName("Categories") CustomFieldParams cfVal = issue.getCustomFieldValue(cf) as CustomFieldParams FormField formfield = getFieldByName("Categories") String warning = "Please select both categories" if (cfVal){ Collection values = cfVal.getAllValues() String v1 = values[0] String v2 = values[1] if (v2 == null) { formfield.with { setValid(false) setTitle (warning) setHelpText("<div class=\"warningBox\">$warning</div>") } } else formfield.setValid(true) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jamie,
I have been trying your revised solution, i.e. :
1
|
cfValues. get ( "CascadingSelect" )?.keySet()?. size () == 2 |
but inside a script, as I will need to run the test from a number of workflow transitions.
I have therefore used :
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
if (cfValues.get('Release - Stream')?.keySet()?.size() == 2) {
//force both fields to be filled in
invalidInputException = new InvalidInputException("You must fill in both fields")
}
and get this error :
MissingPropertyException: No such property: cfValues for class
any assistance greatly appreciated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm not sure what plugin you are talking about... either way, if cfValues is not available, you need to get the cf value yourself, eg:
def customFieldManager = ComponentAccessor.getCustomFieldManager() def customField = customFieldManager.getCustomFieldObjectByName("Release - Stream") def cfVal = issue.getCustomFieldValue(customField) as Map if (cfVal.keySet()...)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Jamie,
the example you gave didn't quite work, as 'ComponentAccessor' wasn't recognised. Presumably because I was only doing :
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
adding
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
seems to have done the trick.
Where can we find the full details and guidelines on these 'things' (i.e. the imported elements) that we need in order to get at JIRA data ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Nick, To use ComponentAccessor you must import {code} import com.atlassian.jira.component.ComponentAccessor {code} Do not use ComponentManager in last versions of Jira API. To find all java doc of Atlassian API : google search, according to componentaccessor it was "jira api componentaccessor" You will find https://docs.atlassian.com/jira/latest/com/atlassian/jira/component/ComponentAccessor.html Best regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am also toying with the post function or groovy script idea - but not sure how to check the value fo the second drop down list. Thoughts?
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.