// restrict editing only to authorized users
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor
import groovy.transform.BaseScript
// Set the base script annotation for field behaviours
@BaseScript FieldBehaviours fieldBehaviours
// Get the custom field by name
def customField = getFieldByName("My Field")
// Retrieve the username of the currently logged-in user
def username = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getUsername()
// Define an array of authorized usernames
def authorizedUsernames = ["Service_Account", "belle_jar"]
// Check if the current user is one of the authorized users
if (!authorizedUsernames.contains(username)) {
// If the user is not in the list, make the field read-only
customField.setReadOnly(false)
} else {
// If the user is in the list, allow editing
customField.setReadOnly(true)
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter