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