You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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);
}
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
According to the app support team, the Behaviors app is not yet available for JSM-type projects. That is why it is not working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.