Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Compare 2 custom field values in Groovy script

Hemanshu Sood
Contributor
September 7, 2018

Hi All,

I need to compare 2 custom field values

Field 1 is a multi select list field containing name of users in a string format. 

Field 2 is derived from below script( which is the display name of the logged in user in jira)

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
String currUserFullName = currentUser.getDisplayName();
log.error("User: $currUserFullName")

Now I need to compare above value to all the values in the multiselect field value. Is it possible?

I started building a script but not able to complete it , please assist:

 

Summary: Current logged in user needs to be compared to Field 1( multi select) selection

1 answer

1 accepted

0 votes
Answer accepted
Nir Haimov
Community Champion
September 7, 2018

Here is a complete code for what you are looking:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfMultiSelectUser = customFieldManager.getCustomFieldObjectByName("name of your field")
def users = issue.getCustomFieldValue(cfMultiSelectUser)

for (int i = 0; i < users.size(); i++) {
if (users.get(i).equals(currentUser)) {
/*if current user exist in the multi user picker list value
do here what ever you want*/
}
}
Hemanshu Sood
Contributor
September 11, 2018

Thank you @Nir Haimov

Suggest an answer

Log in or Sign up to answer