Hello Team,
I am using the Simple Scripted Validator (Scriptrunner) for the Jira workflow as below :-
issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_19742")) && isUserMemberOfRole('Product Managers')
||(issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_19742")) == "Testing Only" && isUserMemberOfRole('Test Leads’))
||(issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_19742")) == "Documentation Only" && isUserMemberOfRole('Documentation Authors’))
||(issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_19742")) == "Research" && isUserMemberOfRole('Development Leads’))
||(issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_19742")) == "Engineering Infrastructure" && isUserMemberOfRole('DevOps Leads’))
This script is trying to ensure that if the custom field of type Select list (single choice) satisfies either of the conditions then only validator allows to proceed, but we have noticed that only 1st part is being validated, and if the first condition fails and second one is true it is not processing.
I also tried an alternative script for testing as below :-
cfValues['Feature Type']?.value == 'Testing Only' && isUserMemberOfRole("Test Leads")
|| cfValues['Feature Type']?.value == 'Documentation Only' && isUserMemberOfRole("Documentation Leads")
In this case also it is not checking the second condition if first one fails.
Please help to identify the cause of why the OR logic is not working for me. Am i missing something.
Thanks and Regards,
Sreedevi
Your code contains errors. You use wrong quotes, check function isUserMemberOfRole
And you can use code like this (If I correctly understood, what you're trying to do):
/*
* Created 2023.
* @author Evgeniy Isaenkov
* @github https://github.com/Udjin79/SRUtils
*/
String cfValue = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_19742"))
if (cfValue && isUserMemberOfRole('Product Managers')) {
// Do something
}
if (cfValue == "Testing Only" && isUserMemberOfRole('Test Leads')) {
// Do something
} else if (cfValue == "Documentation Only" && isUserMemberOfRole('Documentation Authors')) {
// Do something
} else if (cfValue == "Research" && isUserMemberOfRole('Development Leads')) {
// Do something
} else if (cfValue == "Engineering Infrastructure" && isUserMemberOfRole('DevOps Leads')) {
// Do something
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I corrected the quotes it was the error which occurred while copying.
The syntax shows correct, but in this case it only follows the first case and ignores the OR operator and does not validate the remaining conditions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you tried my script above your post?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Evgeniy,
I was trying the script where you have used if else instead of OR operator and it worked fine.
Thanks for your help.
But I am unable to understand why is the OR logical operator failing.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Understood. Let's split first condition to parts:
issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_19742")) && isUserMemberOfRole('Product Managers')
When you check, that value issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_19742")) exists, it returns false. So, whole condition fails.
When you check other OR's - the reason is the same, there is no value, in issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_19742")) == "value"... So conditions don't return true
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh ok... I think I get you now.
Thank you so much for your help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great, @Sreedevi Raman Pisharody !
You're welcome.
If answer helped you, please accept it. It can help other people with similar problems/questions.
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.