Compare user value for 2 user picker fields

m
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2013

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

1 vote
Answer accepted
m
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2013

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

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

1 vote
RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2013

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")
	}

}


RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2013

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

m
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2013

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

All of these provide the same problem.

m
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2013

single user

RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2013

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

m
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2013

Not quite sure what you mean by convert it to Groovy

RambanamP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2013

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!!

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2013

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.

Like Heather R likes this
Teja August 1, 2018

@JamieA

How can I compare Assignee with multi user picker field?

0 votes
Shaikh Moiz January 20, 2014

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
TAGS
AUG Leaders

Atlassian Community Events