Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Make field non editable to users

mbrk
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 6, 2025

Hi Team,

 

We are trying to make Specific field to non-editable to users, somehow expression is not working properly.

I am pasting the expression below, kindly go through and suggest if any errors in these.

 

 

 

// Fields to be updated
const summaryField = getFieldById("customfield_10060");
//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("Administrators"):
        summaryField.setReadOnly(true)
       // descriptionField.setReadOnly(true);
        break;
    default:
        logger.info("No roles were matched. No actions were performed.");
}

1 answer

0 votes
Tuncay Senturk _Snapbytes_
Community Champion
January 6, 2025

Hi @mbrk 

Your script looks good, but there is one thing that is worth changing.

The makeRequest function returns a Response object (as far as I know), and you need to parse the body (use .json()) to access the roles. Something like the below

const getProjectRolesForCurrentUser = await makeRequest(`/rest/api/3/project/${projectId}/roledetails?currentMember=true`);
const roles = await getProjectRolesForCurrentUser.json();
const roleNames = roles.map(item => item.name);

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events