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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

128 views 0 5
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