Forums

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

ScriptRunner Behavior setReadOnly() does not work

Emil Khairov
Contributor
May 21, 2023

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
Emil Khairov
Contributor
May 23, 2023

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 Champion
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

Emil Khairov
Contributor
May 23, 2023

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.

Emil Khairov
Contributor
May 23, 2023

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
Product Admin
TAGS
AUG Leaders

Atlassian Community Events