Skip to main content
Example scripts
arrow icon
To homepage
Jira
Cloud icon
Cloud

Make field read-only based on user groups

Features
Behaviours
Created 1 year ago, Updated 1 month(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira
Language |
typescript
const ticketDepartment = getFieldById("customfield 10205")
const userRegion = getFieldById("customfield 10206")
const ticketCat = getFieldById("customfield 10207")
const priority = getFieldById("priority")

const group = "Example Group";

const user = await makeRequest("/rest/api/2/myself");
if (user) {
    const { accountId } = user.body;
    const userGroups = await makeRequest ("/rest/api/2/user/groups?accountId=" + accountId);
    if (userGroups) {
        const groupNames = userGroups.body.map(({ name }) => name);
        if (groupNames.includes(group)) {
            ticketDepartment.setVisible(false)
            userRegion.setVisible(false)
            ticketCat.setVisible(false)

            priority.setReadOnly(true)
        }
    }
}
Having an issue with this script?
Report it here