Hello
When I write this script in a scripted field
def pliance = getCustomFieldValue("pliance")
log.warn(".."+pliance+"..")
if (pliance.equals("No")){ return 1}
else return 5
pliance is single select drop down. No matter what I select Yes or No, I get value 5
I tried
Log value shows ..No.. properly as expected.
Couple of questions:
1. What is difference of using " vs ' in the if statement
2. Any idea why it is not retuning 1
Thanks
Abe
For Groovy, you can use " and ' interchangeably, as long as you are consistent with each use - "sheep" or 'sheep', but not "sheep' or 'sheep"
Your if statement is not working because the content of a select list field is not a simple string.
When your select list contains "No" for an issue, then pliance.equals('No') is going to be false because the field does not contain "No", it contains an "option" object that represents "No" for you.
The way the option represents something to us is with a "Name", which is a string that the field shows to us on display. So, you can say
if ("No".equals(pliance.getName())
instead, and that will be then doing a string comparison. (swap " for ' if you feel like it)
Hello Nic
Thanks for the response.
If I use .getName it is not working. When I use .getValue() it is working.
It is a bit confusing
def riskCompliance = getCustomFieldValue("pliance")
I thought when I say getCustomFieldValue it will get me value of selected option
So when I say
def pliance = getCustomFieldValue("pliance") // This is basically getting me a option object which has value "No"
if (pliance.equals('No')) // Is comparing with Option object, hence always goes to else
if ("No".equals(pliance.getValue())){ return 1} // It is actually getting me value of option object and hence check passes.
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.