You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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.
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;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Joel Batac , that part of code retrieves list of users stored in custom field Approvers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.