Hi ,
I am using Script runner plugin version 2.1.15, I have written a validation snippet which is working fine when I use the name of the custom field and not the ID, but I don't want my script to be tightly coupled with the custom field name
cfValues['Release'].getValue() == 'True
cfValues['customfield_12345'].getValue() == 'True'
is not, any suggestions?
Look up the CF by ID...
def customFieldManager = ComponentAccessor.getCustomFieldManager() def cf = customFieldManager.getCustomFieldObject(12345) return issue.getCustomFieldValue(cf)?.value == "True"
Hi @Jamie Echlin [Adaptavist] - My full statement involves multiple fields - issue.issueTypeObject.name != 'XYZ' || (issue.issueTypeObject.name == 'ABC' && cfValues['Release'].getValue() == 'True' && cfValues['myField'] && cfValues["myNewField''] && cfValues['MyFieldtwo']?.value?.size() > 0)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
for other readers - Here "Release" is the select dropdown where as the "myfield", "mynewfield" are of type Text field thus if they are null groovy will interpret them as false.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't really see what the problem is... if you don't want to hard-code the name you need to hard-code the ID. Personally I prefer name because it's portable between instances. In your case you need to get multiple fields by multiple IDs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I actually hard-coded the ID using the cfValues['customfield_1234'] convention but that didn't work, i guess to make it work using the IDs is by using what you shared i.e. extracting the IDs using the customFieldManager
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes. cfValues is indexed only by *name*.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
but it's just a convenience... if you don't want it then you should cfm to get the custom field by ID.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks for sharing more info about it, as my requirement involved writing a long validation statement consiting of a certain scenario involving multiple custom fields and I wanted to restrict it to a single line of code but since cfValues doesn't work well with IDs thus would need to extract the IDs before hand.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
no need to stick to a single line of code, write as much as you need to to make it clear
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What kind of custom field is your field? It will affect the way you retrieve the value from it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Sana Safai - Yes, ofcourse it would have an impact on the sytax based on the type of my custom field but I currently not concerned with that rather I am looking for a way to get the custom field values based on their ID instead of names in a long condition statement, see my comment in response to Jamie answer's. thanks
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.