Make field required based on another field on Jira cloud

Narsha Bac
Contributor
April 10, 2023

Can we set a custom field mandatory based on a selected value of another field on Jira cloud via scriptrunner upon closure of an issue?

For e.g., I have a custom field (can be checkbox or dropdown) named 'Has caused a delay?'. When the value for this field is Yes, then another field 'Details' will become mandatory. If the field 'Has caused a delay?' is no, then the field 'Details' is not mandatory.

I know we can do this via scriptrunner, and I am new to coding. Can someone help on this please? 

Or if there is another way around to achieve this?

Regards,

Narsha

1 answer

1 accepted

3 votes
Answer accepted
Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 10, 2023

Hi @Narsha Bac and welcome to the community,

I found it more easy to use JMWE for such cases. You can add a workflow validator (Field Required Validator (JMWE app)) on your transition like the following:

required if.png

Replace Agent Solution with Details and customfield_10177 with the id of your "Has caused a delay" customfield.

Narsha Bac
Contributor
April 10, 2023

Hi Alex,

Thanks for the prompt response but unfortunately I cannot use this app as it is not free. Any other alternatives please?

Best Regards,

Narsha

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 10, 2023

Then try this:

issue.customfield_10004.value == "Yes" ? issue.customfield_10221 != null : false

And replace "10004" with the id of the custom field of "Has caused a delay". Test it and let me know.

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 10, 2023

Aaand replace the customfield_10221  with the id of your "details" field

Narsha Bac
Contributor
April 10, 2023

I entered the script you gave me on the validator part on the workflow but I am getting this error:

{

"timestamp": "2023-04-10T09:17:25.580Z",

"webhookEvent": "jira_expression_evaluation_failed",

"expression": "issue.customfield_13161.value == \"Yes\" ? issue.customfield_10237 != null : false",

"errorMessages": [ "Evaluation failed: \"issue.customfield_13161.value\" - Unrecognized property of `issue.customfield_13161`: \"value\" ('value'). Type null does not have any properties" ],

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 10, 2023

@Narsha Bac what type is customfield_13161? Text, single select, or something else?

In addition let me also know the type of customfield_10237

Narsha Bac
Contributor
April 10, 2023

customfield_13161 is a single select field and customfield_10237 is a text field (multi-line).

Can you please let me know the code you provided to me works for which type of field if not the ones I mentioned?

Thanks

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 10, 2023

@Narsha Bac the above code should work for a single select and for the corresponding multi-line text. Can you paste a screenshot of your validator?

Narsha Bac
Contributor
April 10, 2023

This is my validator:

Pic 1.pngPic 2.png

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 10, 2023

@Narsha Bac this shouldn't happen, or I am missing something. When do you receive this message? After doing what exactly and what value does the 13161 CF has?

Narsha Bac
Contributor
April 11, 2023

Hi Alex,

I mistakenly answered to my own post instead of replying to you. Can you delete my answer on the community please? 

The message I sent is when I checked the logs in the workflow. I managed to make it work, not sure what was wrong.

However, it is not working as expected. When I select another value for the CF 13161, for e.g. 'No', I am still getting the other field as required. CF 13161 has values: None, Yes and No.

Thanks.

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 11, 2023

@Narsha Bac 

Hi Alex,

The message I sent is when I checked the logs in the workflow. I managed to make it work, not sure what was wrong.

However, it is not working as expected. When I select another value for the CF 13161, for e.g. 'No', I am still getting the other field as required. CF 13161 has values: None, Yes and No.

I knew there was something wrong with the line of code yesterday, but that wasn't important till we solved the error problem. Now that the error is solved, let me get back to the drawing board and get back to you!

Narsha Bac
Contributor
April 11, 2023

Thanks a lot Alex. Looking forward to your response.

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 11, 2023

@Narsha Bac 

Try the following:

issue.customfield_13161?.value == "Yes" ? issue.customfield_10237 != null : true

 Now it ought to be ok! I've tested it on my instance, and I think it works the way you want it!

Like # people like this
Narsha Bac
Contributor
April 11, 2023

Yes! It is now working as expected. 

Thanks a lot for your help Alex.

Best Regards.

Alex Koxaras _Relational_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 11, 2023

@Narsha Bac good to know that!

Kindly mark my answer as accepted in order to help others in the community with similar questions. Thank you :)

Suggest an answer

Log in or Sign up to answer