Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,422
Community Members
 
Community Events
184
Community Groups

ScriptRunner Behavior setReadOnly() does not work

Hello,

 

I am trying to run a ScriptRunner on load. The particular behavior is to restrict field editing to administrators only. However, it is not working. I have logged in as a simple agent and the field that I am targeting is still editable.

This is the script that I am running:


const user = await makeRequest("/rest/api/2/myself");

const { accountId } = user.body;

const getRoles = await makeRequest(`/rest/api/2/user/groups?accountId=${accountId}`);

const roleNames = getRoles.body.map(({ name }) => name);

/* Select role for priority field to be displayed... */

const role = "Administrators";

if (!roleNames.includes(role)) {

getFieldById("customfield_10174").setReadOnly(true);

}

2 answers

1 accepted

0 votes
Answer accepted

According to the app support team, the Behaviors app is not yet available for JSM-type projects. That is why the app is not working yet.

2 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 22, 2023

Hi @Emil Khairov

I have run a basic test in my environment and don't seem to be encountering any issues.

Below is the sample code that I have tested with:-

const user = await makeRequest("/rest/api/2/myself");

const { accountId } = user.body;

const getRoles = await makeRequest(`/rest/api/2/user/groups?accountId=${accountId}`);

const roleNames = getRoles.body.map(({ name }) => name);

const role = "administrators";

const textField = getFieldById("customfield_10109");

textField.setValue('Testing 123')

if (!roleNames.includes(role)) {

textField.setReadOnly(true)

}

Please note that the sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

In your code, I noticed that you had declared the role as:-

const role = "Administrators";

This seems to be the error in your code.

Please change it to lowercase as shown below:- 

const role = "administrators";

I hope this helps to solve your question. :-)

Thank you and Kind regards,

Ram

Hello,

 

Thank you for the suggestion. However, I have contacted the ScripRunner support team and they have confirmed that Behaviours is not yet available for JSM type of projects. Therefore, they simply won't work for now.

According to the app support team, the Behaviors app is not yet available for JSM-type projects. That is why it is not working.

Suggest an answer

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

Atlassian Community Events