Add Helper Text to Locked Field using a Behaviour

Kmmaughs
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.
February 25, 2021

We have scriptrunner. I'm using a Behaviour to lock a field for editing. There is an exception. If a user is a part of a specific group, the field can be edited. If the user is not in that group, the field is locked. 

Is there a way to show some helper text to a user not in the group that the field is locked because they're not in the group? 

1 answer

1 accepted

2 votes
Answer accepted
C_ Derek Fields
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.
February 25, 2021

This code should do it for you:

import com.atlassian.jira.component.ComponentAccessor;

final String permittedGroup = "GROUP";
final String protectedField = "Field";

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
def groupManager = ComponentAccessor.getGroupManager();
def valid = groupManager.getGroupsForUser(currentUser).find {it.getName() == permittedGroup}
def field = getFieldByName(protectedField);

if (valid == null) {
field.setDescription("Only members of $permittedGroup can edit this field");
field.setReadOnly(true);
} else {
field.setDescription("Please edit this field");
field.setReadOnly(false);
}
Kmmaughs
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.
February 26, 2021

That did it. Thank you!

Suggest an answer

Log in or Sign up to answer