Conditional expression - validator - make comment mandatory when resolution is "X" value

arama mihai
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.
August 3, 2021

Hello, while in Jira Cloud, using Scriptrunner, I am trying to add a validator that will make the comment field mandatory on a transition, if the resolution is set to "Cannot Reproduce". 

I am trying to use conditional-expressions, but I haven't been able to find the proper way for it:

issue.resolution == 'Cannot Reproduce' ? issue.comments.length > 0

Please let me know how this would need to be written.

Thank you!

1 answer

1 accepted

3 votes
Answer accepted
Khairul Danial August 3, 2021

Hi arama, I don't think you will need to use conditional-expression in this case. Base on your condition I think you can do it like such :

issue.resolution?.name != "Cannot Reproduce" || (issue.resolution?.name == "Cannot Reproduce" && issue.comments.length>0)

This will return true if you set the resolution to other than  "Cannot Reproduce"(Done e.g) OR it will return true when resolution is set to "Cannot Reproduce" and contains comment to it.

Based on your original condition seems like you did not refer to the resolution correctly.
You can checkout the Jira Expression Type in this documentation too: https://developer.atlassian.com/cloud/jira/platform/jira-expressions-type-reference/#resolution


Try it out and see whether this fix your issue

arama mihai
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.
August 4, 2021

Hello @Khairul Danial ,

Thank you for your reply. Your validator works almost as expected. But there is one major factor to be taken into consideration. It checks for comments entered on the issue at any moment (prior to the transition), but I would need it to prevent the transition if the resolution is "Cannot Reproduce" and a comment is not entered in the current transition screen.

Please let me know if you think that is possible. 

FYI, on server it was: 

issue.resolution?.name != 'Cannot Reproduce' || transientVars["comment"]

 

Best regards,

Mihai

arama mihai
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.
August 4, 2021
issue.resolution?.name != "Cannot Reproduce" || (issue.resolution?.name == "Cannot Reproduce" &&   issue.comments.filter(comment => comment.id == null).length ==1)
Like Vikrant Yadav likes this

Suggest an answer

Log in or Sign up to answer