Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,555,754
Community Members
 
Community Events
184
Community Groups

Jira Behaviour - Check if user is part of 'Approvers' user picker field

Hi,

 I'm wondering how to check/compare if the current user is listed in a user-picker filed named Approvers. I want to hide a field if the user doesn't belong (or listed) in the field. 

 

Thanks. 

1 answer

0 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 07, 2023

Hi @Joel Batac ,

please try the following code :

import java.util.List;

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.user.ApplicationUser;

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
CustomField approversCF = customFieldManager.getCustomFieldObjectByName("Approvers");

Issue issue = getUnderlyingIssue();
def field = getFieldByName("YOUR_FIELD_NAME_HERE");

List<ApplicationUser> approvers = issue.getCustomFieldValue(approversCF)!=null?(List<ApplicationUser>)issue.getCustomFieldValue(approversCF)):null;
if(approvers.contains(currentUser))){
field.setHidden(false);
} else {
field.setHidden(true);
}

Hope this helps,

Fabio

Thanks Fabio. I new to scriptrunner. Can you explain this part?

 

List<ApplicationUser> approvers = underlyingIssue?.getCustomFieldValue(approversCF)!=null?(List<ApplicationUser>)underlyingIssue?.getCustomFieldValue(approversCF):null;

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 08, 2023

Hey @Joel Batac , that part of code retrieves list of users stored in custom field Approvers.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events