Compare user value for 2 user picker fields

Is it possible to compare 2 user values for 2 different user picker custome fields and to block a transition based on this being true?

3 answers

1 accepted

cfValues['User picker field1'] != cfValues['User picker field2']

That worked thanks! Not sure why it was not working before when I tried it.

did you tried like this?

cfValues['User picker field1']?.name== cfValues['User picker field2]?.name

the following code we are using in our plugin, you have to conver it to groovy
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.crowd.embedded.api.User;
 
CustomFieldManager cfm = ComponentAccessor.getCustomFieldManager();
CustomField cfField1 = cfm.getCustomFieldObjectByName("Field1");
CustomField cfField2 = cfm.getCustomFieldObjectByName("Field2");
User user1 = (User) issue.getCustomFieldValue(cfField1);
User user2 = (User)issue.getCustomFieldValue(cfField2);
 
 
if(user1 !== null && user2 !=null){
	if((user1.getName()).equal(user2.getName())){
		s.o.p("both field values are equal")
	}

}


is those custom fields are sing user picker or multiuser picker?

Yes but gives false result. also tried with *.value and only .value

All of these provide the same problem.

i have update my answer check that, i think we have to use cfValues['User picker field1']?.name to get user name from user picker custom field

Not quite sure what you mean by convert it to Groovy

what i gave code is used on our java plugin but you are executing this on groovy script runner so that's why i said to convert to groovy!

i don't have much knowledge on groovy but i think it is almost same, you can try as it is on my answer!!

cfValues['User picker field1'] != cfValues['User picker field2']

should be sufficient. If that doesn't work they aren't equal, or they are different types. Use admin -> built-in scripts -> condition tester.

Hello Jamie,

Can I kow how can i compare None value/Option for the custom field of type select,

I want to restrict users from performing the transition unless the value of my custom field equals to None,

Can you please help..

Thanks and regards,

Moiz Shaikh.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

176 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you