Example scripts
To homepage
Jira

Limit work item types based on user role
App in script

ScriptRunner For Jira
by Adaptavist
Compatibility

Jira
Language |
typescript
// Note: You should run this script by selecting "On load" in the check box above.
const context = await getContext();
const spaceId = context.extension.project.id;
const spaceRoles = await makeRequest(`/rest/api/3/project/${ spaceId }/roledetails?currentMember=true`);
const spaceRoleNames = spaceRoles.body.map(role => role.name);
const workItemTypeField = getFieldById("issuetype");
const allowedWorkItemTypeIds = ['10133', '10134']; // IDs for Story and Task
if (spaceRoleNames.includes('Developers')) {
workItemTypeField.setOptionsVisibility(allowedWorkItemTypeIds, true);
if (!allowedWorkItemTypeIds.includes(workItemTypeField.getValue()?.id)) {
workItemTypeField.setValue("10133"); // Default to Story if the current value is not allowed
}
}
Having an issue with this script?
Report it here