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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.