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
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:
Replace Agent Solution with Details and customfield_10177 with the id of your "Has caused a delay" customfield.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Aaand replace the customfield_10221 with the id of your "details" field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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" ],
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Narsha Bac what type is customfield_13161? Text, single select, or something else?
In addition let me also know the type of customfield_10237
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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?
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.
@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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
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.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes! It is now working as expected.
Thanks a lot for your help Alex.
Best Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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 :)
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.