How to make both fields required in Cascading Select field

SARAVANAKUMAR February 26, 2019

 Using JIRA CLOUD

The Cascading Select custom field consists of two drop-down lists. Currently in the 'required' mode of this field, only the existence of a value in the first drop-down is validated. In some scenarios this may be not enough. i want to set both parent and child option must be set in 'required' mode.

thanks,

Saravana Kumar

7 answers

6 votes
David Luke February 11, 2021

Jira Workflow Toolbox (JWT) offers a validator for making a field required, and it works for both levels of cascading select fields. GUI-configurable. No coding or scripting required.

3 votes
Scott Fannen January 18, 2023

Hi there,

Just in case this helps, (in Jira Cloud) I had a cascading field in a service desk request type - and wanted to make sure both parts of the cascading field were filled in.

The "Required" option takes care of the "parent" menu, but not the child.

You can't seem to validate it using any of the native validators as far as I can see - regular expression check won't even see cascading fields.

We do have ScriptRunner though - something I usually try to avoid (not because it's bad - it isn't - but if you're not used to scripting it's nice to avoid for myself or anyone taking over from me).

I tried various versions of "checking both parts were full" like this cfValues['your cascading field']?.values()*.value.size() == 2 with no luck,

Since I was only checking the child though, this worked:

issue.customfield_13997.child.value != ""

I tried earlier with 0 or NULL - that didn't work but I'm happy now.

Also in case anyone is wondering where it goes - if you have ScriptRunner, "ScriptRunner Script" appears in the validator options - and you just type it in as is. I'm not sure if you can put the real field name but the field ID can be obtained by editing the custom field and looking in the URL.

Just posting this in case anyone is looking again - and in case the underpinnings of Jira have changed a bit - this works at this point.

Scott

2 votes
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 27, 2020

most previous answers were for Jira Server. On Jira Cloud, conditions and validators can only be written using Jira expressions, a language created by Atlassian. 
You can use the Issue Fields help tab below the editor to find out how to test your cascading select field. It will be something like:

issue.customfield_12345 && issue.customfield_12345.child.value
Kaviraj January 30, 2020

Hi @David Fischer 

Thanks for your response. Its working fine.

issue.customfield_12345 && issue.customfield_12345.child.value
Like Dionisio Valdes H likes this
Robson Carvalho October 10, 2021

Hi Kaviraj,

Would you mind to share printscreen pointing where I should add this expression? I am pretty new to JIRA and kind of lost.

Like Cyan Lee likes this
Atlassian Learner May 29, 2023

Hi @David Fischer 

I kindly request your assistance with an additional requirement. I successfully implemented your expression in the Built-in script, and it's working well.

However, we now need to restrict this functionality to only certain request types. Specifically, if the request types are "General IT" or "Access Request," we would like both the parent and child fields for cascading to be mandatory.

Thank you in advance for your continued support.

Best regards,

Ajay

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 30, 2023

Hi @Atlassian Learner ,

you can amend the expression this way:

!["General IT","Access Request"].includes(issue.issueType.name) || issue.customfield_12345 && issue.customfield_12345.child.value
Atlassian Learner May 31, 2023

Thanks @David Fischer ,

I have amended the expression to match the Customer request types, like this 

!["General IT","Access Request"].includes(issue.customfield_12400.requestType.name) || issue.customfield_24329 && issue.customfield_24329.child.value 

But the child field was mandatory for all request types, not just for 2. Am I missing anything in the above expression? "||" refers to OR conditions, which might be the issue. I added "&&" between the customer request type and field value condition, but it did not work well.

fyi, Error message: Evaluation failed: "issue.customfield_12400.requestType" - Unrecognized property of `issue.customfield_12400`: "requestType" ('requestType'). Type null does not have any properties

We need L2 value mandatory if the Customer request form is "General IT" or "Access Request,"

Thanks again,

Ajay

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 31, 2023

Hi @Atlassian Learner 

for some reason you replaced

issue.issueType.name

with

issue.customfield_12400.requestType.name

in your script. Please revert to 

issue.issueType.name

 

Anand R July 4, 2023

Hi @David Fischer  - Could you please share the screen shots if it possible, i have created the cascading field but in the validator expression that fiel is not showing up

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 4, 2023

@Anand R I'm not sure what screenshots you need. What do you mean by "i have created the cascading field but in the validator expression that field is not showing up"?

Anand R July 5, 2023

Yes

David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 5, 2023

@Anand R 

"Yes" does not answer my question...

Raghu Mani February 10, 2024

Can I not do this without script runner ?

Like L M likes this
0 votes
Muhammad Akram Sharifi October 26, 2022

Hi Everyone

Using JMWE I have added required field validation with condition bellow statement is working for me

"!!issue.customfield_12345 && issue.customfield_12345.value == "Alert" && issue.customfield_12345.child.value == null"

please accept the answer if that works for you.

0 votes
Bridy Frett January 27, 2020

Hi @Kaviraj

It looks like there are significant differences between the on-prem and sever versions.  I did a bit of browsing on the JMWE site and it looks like it uses a different process to get data.  https://innovalog.atlassian.net/wiki/spaces/JMWEC/pages/108200055/User+created+custom+fields (Cascading section)  Based on the accessing a field of cascading type, you may want to try something like this:

{{ issue.fields['Cascading field'].child.value }} != null

or maybe

{{ issue.fields["Cascading field"] | field("child.value) }} != null

Unfortunately I don't have a cloud instance already configured to try this.

Bridy

Kaviraj January 30, 2020

Hi @Bridy Frett 

Thank you for your effort & response.

I have included below JIRA expression & its working fine.

issue.customfield_12345 && issue.customfield_12345.child.value
Robson Carvalho October 10, 2021

Hi @Bridy Frett @Bridy Frett

Would you mind to share printscreen pointing where I should add this expression? I am pretty new to JIRA and kind of lost.

Like L M likes this
0 votes
Bridy Frett June 2, 2019

Hi @SARAVANAKUMAR 

In the workflow, on the Create transition, in the list of Validator options, you'll see an option called "Script Validator [ScriptRunner]"

Bridy

Kaviraj January 5, 2020

Hi @Bridy Frett @Sreenivasaraju P 

Using JIRA Cloud version.

Followed you steps from your comment, but didn't find the clue. I have ended up with the below page. kindly help me out to add 

cfValues['your cascading field']?.values()*.value.size() == 2

 

Workflow validation.PNG

Bridy Frett January 5, 2020

I'm afraid the Script Runner plug-in is required for that solution.

I did find also find a solution using Jira Misc Workflow Extensions, but that is another app and it doesn't look like you have it.

I don't believe it's possible with the core Jira logic.

Like Rodrigo Mieres likes this
Kaviraj January 6, 2020

Hi @Bridy Frett 

I have added Jira Misc Workflow to test it.

few validations are added. 

Workflow validation 02.PNG

Let me know the next step to make cascading field mandatory for second value.

Thanks a lot.

Bridy Frett January 14, 2020

Hi @Kaviraj

Use the "Linked issues Status Validator."  In the groovy script field, enter the following:

issue.get("customfield_19900")?.get("1")?.optionId != null

Adjust your custom field ID as needed.  get("1") refers the second field of the cascading list.

Bridy

Kaviraj January 15, 2020

Hi @Bridy Frett 

Thanks for your response

I have included above script with my Custom field ID.

But still i have an error when creating Issues even-though selected cascading second value.

Workflow validation 03.PNG

Bridy Frett January 22, 2020

Based on the error, I think you are using the wrong validator.  It's called "Scripted (Groovy) Validator (JMWE add-on)" on the validator page.

Here's a screenshot of my implementation:

cascade field.png

Kaviraj January 27, 2020

Dear @Bridy Frett 

Ya, I got your point.

This time i tried below mentioned Validator. (Refer Image 1)

Image 1

Workflow validation 04.PNG

After that, added your script. (Refer Image 2)

Image 2

Scripted 01.PNGBut Still i got error.

Validator 01.PNG

Error detail Snap below

Error Detail 01.PNG

It will be so helpful if you let me know where i went wrong.

 

Thanks

0 votes
Sreenivasaraju P
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 26, 2019
SARAVANAKUMAR February 26, 2019

Hi @Sreenivasaraju P 

   how to add "Script Validator", i don't have option in script runner. Please share some steps to add "Script Validator"

where i have to add this line "cfValues['your cascading field']?.values()*.value.size() == 2"

i only having below options.

script runner.png

thanks,

Saravana Kumar 

Natalia Trofimov November 30, 2021

Hi @David Fischer  

the validator below is working for us as well. Is it possible to make the validator for only one parent/child value in the cascade list? i.e. only for "option 1" in the parent list

!! issue.customfield_12345 && !! issue.customfield_12345.child.value

 

Natalia Trofimov December 1, 2021

Please discard my question

Suggest an answer

Log in or Sign up to answer