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

Make Fields Editable to only users in a certain role

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
// Fields to be updated
const summaryField = getFieldById("summary");
const descriptionField = getFieldById("description")

// Get the projectId out of the context
const context = await getContext();
const projectId = context.extension.project.id

// Return all project roles the current user belongs to
const getProjectRolesForCurrentUser = await makeRequest(`/rest/api/3/project/${projectId}/roledetails?currentMember=true`);

// Get the name of each project role the user belongs to
const roleNames = getProjectRolesForCurrentUser.body.map(item => item.name);

// Switch on each role and update fields if conditions met
switch (true) {
    case roleNames.includes("Developers"):
        summaryField.setName("Ticket Summary");
        descriptionField.setName("Ticket Description");
        break;
    case roleNames.includes("Administrators"):
        summaryField.setReadOnly(true)
        descriptionField.setReadOnly(true);
        break;
    default:
        logger.info("No roles were matched. No actions were performed.");
}
Having an issue with this script?
Report it here