Limit issue types based on user group? Jira ScriptRunner

Rodrigo Gomez February 3, 2025

Hello, I have been trying to limit the issue type based on the user group to specific project with no success via Behaviours on Jira ScriptRunner.

Example User belongs to the group JIRAtests should only be available to create issuetypes A and B, while users that do not belong to JIRAtest should be able to create issue types A, B and C

 

I was trying to achieve this via Scriptrunner behaviors but no success at all.


 

const issueTypeField = getFieldById("issuetype")

const user = await makeRequest("/rest/api/2/myself");
const { accountId } = user.body;
const userGroups= await makeRequest("/rest/api/2/user/groups?accountId=" + accountId);
const groupNames = userGroups.body.map(({ name }) => name);

// Select the group that the specific issue types will be shown for.
const group = "JIRAtest";

if (groupNames.includes(group)) {
    issueTypeField.setOptionsVisibility(["10040", "10011"], true)
}
Is there another way or is there something wrong on the code?  thanksScreenshot 2025-02-03 155556.png

2 answers

1 vote
Joseph Chung Yin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 3, 2025

@Rodrigo Gomez -

In addition to what @Trudy Claspill pointed out on the syntax error, please kept in mind that in JSM what users sees are the Request Types to create his/her issues for your JSM project.

Request Type is based on the IssueType allowed in your project.  So are you asking to restrict request types access based on group association?  If, take a look at this reference link out of the box for JSM to restrict request type access for issue creation (without using Behavior setup) -

https://support.atlassian.com/jira-service-management-cloud/docs/add-or-remove-restrictions-on-request-types/

Hope this helps.

Best, Joseph Chung Yin

 

1 vote
Trudy Claspill
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 3, 2025

Hello @Rodrigo Gomez 

I think the syntax of your line here is incorrect:

 

const userGroups= await makeRequest("/rest/api/2/user/groups?accountId=" + accountId);
Looking at the example code in this video from Adaptavist:
... the code should be
const userGroups= await makeRequest("/rest/api/2/user/groups?accountId=${accountId}");

Suggest an answer

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

Atlassian Community Events