Uploaded image for project: 'Jira Data Center'
  1. Jira Data Center
  2. JRASERVER-10302

Ability to make both fields required in Cascading Select CF

    • 3
    • We collect Jira feedback from various sources, and we evaluate what we've collected when planning our product roadmap. To understand how this piece of feedback will be reviewed, see our Implementation of New Features Policy.

      NOTE: This suggestion is for JIRA Server. Using JIRA Cloud? See the corresponding suggestion.

      At the moment a Cascading Select Custom Field that is marked as required, will pass if only one field is selected.
      At the moment this is outside the scope of the custom field.

            [JRASERVER-10302] Ability to make both fields required in Cascading Select CF

            How to make a cascading field second level required only if second level there.

            Shaik siddik added a comment - How to make a cascading field second level required only if second level there.

            Teja, for your case where items might be childless... When the HashMap only has only selected item, you can pass its ID to OptionsManager.findByParentId(Long).  If that's not empty, it means the item has children that the user should have selected so you can make your validator fail.

            David Dunham added a comment - Teja, for your case where items might be childless... When the HashMap only has only selected item, you can pass its ID to OptionsManager.findByParentId(Long).  If that's not empty, it means the item has children that the user should have selected so you can make your validator fail.

            Teja added a comment -

            How to make a cascading field second level required only if second level there.

            A

            A1, A2

            B

            B1, B2

            C

            No second level

            Teja added a comment - How to make a cascading field second level required only if second level there. A A1, A2 B B1, B2 C No second level

            I tried to but is not working somehow.
            no error and the transition pass.
            I tried to have a simple script-runner validator and it works.
            The code is : cfValues[}}{{"The name of your customfield"}}{{]?.keySet()?.size() == 2
            https://scriptrunner.adaptavist.com/4.3.4/jira/recipes/workflow/validators/simple-scripted-validators.html#_validating_cascading_selects 

            AYMEN JEBRI added a comment - I tried to but is not working somehow. no error and the transition pass. I tried to have a simple script-runner validator and it works. The code is :  cfValues [}}{{"The name of your customfield"}}{{] ?.keySet()?.size() == 2 https://scriptrunner.adaptavist.com/4.3.4/jira/recipes/workflow/validators/simple-scripted-validators.html#_validating_cascading_selects  

            Try using this slight variation:

            import com.atlassian.jira.component.ComponentAccessor
            import com.atlassian.jira.issue.MutableIssue

            def issue = issue as MutableIssue
            def cascadingSelect = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)?.findByName("Cascading Field Name")
            def values = issue.getCustomFieldValue(cascadingSelect) as HashMap

            // Will return true if both the parent and child options in the Cascading Select have a value
            def keySetSize = values?.keySet()?.size()
            keySetSize == 2

            Bridy Frett added a comment - Try using this slight variation: import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue def issue = issue as MutableIssue def cascadingSelect = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)?.findByName("Cascading Field Name") def values = issue.getCustomFieldValue(cascadingSelect) as HashMap // Will return true if both the parent and child options in the Cascading Select have a value def keySetSize = values?.keySet()?.size() keySetSize == 2

            I have added the last link in the workflow in the creation field and somehow the code is not working for me.
            The script is not showing any error in the logs but the transition pass

            AYMEN JEBRI added a comment - I have added the last link in the workflow in the creation field and somehow the code is not working for me. The script is not showing any error in the logs but the transition pass

            larry.lowe added a comment -

            I used the code posted by @David Lawless, and it worked fine. No errors. Just input your custom field name here: findByName("CascadingSelect")

            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
            

            larry.lowe added a comment - I used the code posted by @David Lawless, and it worked fine. No errors. Just input your custom field name here: findByName("CascadingSelect") 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

            Using Jira 7.10 I have been trying to get the ScriprtRunner workaround referenced above, namely adding

            "cfValues.get['your_ cascading_field_name']?.key.set()?.size() == 2" as a simple scripted validator.

            https://scriptrunner.adaptavist.com/4.3.4/jira/recipes/workflow/validators/simple-scripted-validators.html#_validating_cascading_selects

            However 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 someone

             

             

            David Lawless added a comment - Using Jira 7.10 I have been trying to get the ScriprtRunner workaround referenced above, namely adding "cfValues.get ['your_ cascading_field_name'] ?.key.set()?.size() == 2" as a simple scripted validator. https://scriptrunner.adaptavist.com/4.3.4/jira/recipes/workflow/validators/simple-scripted-validators.html#_validating_cascading_selects However 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 someone    

            spent unnecessary cycles on this issues.  Atlassian is not providing enough details as to why child filed is not becoming mandatory.   Their answer is to purchase ScriptRunner is not acceptable.   Why are they even allowing Cascading select fields if they have this many issues.

            Jay Kantaria added a comment - spent unnecessary cycles on this issues.  Atlassian is not providing enough details as to why child filed is not becoming mandatory.   Their answer is to purchase ScriptRunner is not acceptable.   Why are they even allowing Cascading select fields if they have this many issues.

            Does the description to this ticket mean that this defect will never be in scope nor actually resolved?

            Blair Dickey added a comment - Does the description to this ticket mean that this defect will never be in scope nor actually resolved?

              Unassigned Unassigned
              nick.menere Nick Menere [Atlassian] (Inactive)
              Votes:
              55 Vote for this issue
              Watchers:
              91 Start watching this issue

                Created:
                Updated:
                Resolved: