Hi,
To validate the condition of a transition I must be able to compare the name of a user entered in an issue field and the lead associated with the selected component in the same issue.
I have found two solution based on ScriptRunner :
The first to compare two field :
cfValues['Field1'] == cfValues['Field2']
The second to find the lead of the first component selected in an issue
package com.onresolve.jira.groovy.test.scriptfields.scripts
def components = issue.componentObjects.toList()
if (components) {
return components?.first()?.componentLead
}
But when i want to merge to compare the component lead and a field it doesn't work.
package com.onresolve.jira.groovy.test.scriptfields.scripts
def components = issue.componentObjects.toList()
if (components) {
return components?.first()?.componentLead
}
For example :
package com.onresolve.jira.groovy.test.scriptfields.scripts
def components = issue.componentObjects.toList()
if (components) {
return components?.first()?.componentLead == cfValues['Field1']
}
Can you help me ?
Regards
Field == Field only comes out as true when the content of the fields are the same. The fields you're comparing are of two different types, let alone content, so they'll never compare the same.
It's a bit like comparing an apple with a kiwi - one aspect of both is that they're green, but your equivalence question is "is this apple the same as a kiwi?".
What you need to do is extract the aspects that you actually want to compare from each object, so using the fruit in a pseudo-code example, don't ask "apple == kiwi", but "apple.colour == kiwi.colour".
Your code already does that for components, it's getting a user object back from the componentLead call, but it's then trying to compare that user object with the content of a field. Unless that field also contains a user object, it's not going to work. So, you might assume that means that it should work if your Field1 is a single user picker (any other field type won't hold a single user as the content)
It probably won't though. Atlassian wrap select-list field content in singleton arrays in some places and I think they do it with the user picker - the content coming back from cfValues[Field1] will be an array with one element that contains a user, so you'd need to extract that. On top if that, there are several object types of user, so you may need to come up with another comparison again!
So, I think you might be looking at something more like:
components?.first()?.componentLead.getName() == cfValues['Field1'].first.getName()
if the fields hold different types of user and Field1 is in an array.
You'd need to look at the class definitions for the user objects if you want to compare on something else
Many thanks, I have adapted my code as below and it's work...
package com.onresolve.jira.groovy.test.scriptfields.scripts
def components = issue.getComponents()
if (components) {
if (components?.first()?.componentLead.getName() == cfValues['Field1'].getName()) {
return true;
}else{
return false;
}
}else{
return false;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.