Restricting to a Single Issue Type by Scriptrunner Behaviours

denizkaradal November 9, 2020

Hi all,

After searching how I can restrict to single issue type, I came accross with a solution offered by Behaviours.

https://scriptrunner.adaptavist.com/6.9.1/jira/recipes/behaviours/restricting-issue-types.html

The problem I face;

The code snippet has no effect on my side. I use Scriptrunner 6.9.1. I added my group into a role i.e "Extern". This group is only available in "Users" role and "Extern" role. "Users" role has "Browse projects" and "Create Issues" permissions.

After adjusting the code snippet, the user is still able to see all issue types.

import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.security.roles.ProjectRoleManager

import static com.atlassian.jira.issue.IssueFieldConstants.ISSUE_TYPE

def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def remoteUsersRoles = projectRoleManager.getProjectRoles(user, issueContext.projectObject)*.name
if (remoteUsersRoles == ["Extern"]) {
    def constantsManager = ComponentAccessor.getConstantsManager()
    def queryIssueType = constantsManager.getAllIssueTypeObjects().find { it.name == "Bug" }
    getFieldById(ISSUE_TYPE).with {
        setFormValue(queryIssueType.id)
        setReadOnly(true)
    }
}

Is there something wrong with the code snippet or what needs to changed in my case.

Any help much appreciated.

 

1 answer

0 votes
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 9, 2020

Hi @denizkaradal,

I don't find any issue with your snippet except IF condition you placed

your user is part of Extern and Users role but your script checks if users is JUST part of EXTERN role

the value of remoteUsersRoles is ["Extern", "Users"](If I'm not wrong)

you may want to try out the snippet by adjusting IF condition as below

if ("Extern" in remoteUsersRoles){
     //code here
} 

 Hope this helps

 

BR,

Leo

denizkaradal November 10, 2020

Hi @Leo 

It seems working but I got the following strange behaviour.

  1. When the user opens up the create screen for the project, only "Bug" issue type is being shown(so far so good)
  2. but if the user ever switches into another project in which he/she has an access, normally all available issue types are being displayed for another project.
  3. in the end if the user again switches back to project in which this "Behaviour script" was activated for issue type "Bug", you then see again all available issue types in the project.
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 10, 2020

@denizkaradal,

I would suggest you to map your behaviour script for Project field and your script as server side script

so that every time project field is changed the behaviour runs again which may fix your issue

 

BR,

Leo 

denizkaradal November 10, 2020

@LeoI am not sure how it is done. I have already mapped it on a project and chose a issue type by using "Use project/issuetype mapping". Is there any more configuration? because I do not see any. Could you help me with it?

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 10, 2020

below screen shot may give you some idea

 

behaviour-field-selection.png

denizkaradal November 11, 2020

Please check my screenshot but I do not see any options like you have. Is there due to version or do I miss something?

hmdl.JPG

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 11, 2020

I see you've placed the script in initializer, if you notice the bottom of the screen shot, there is a field called "Add field". choose Project from there and once you added you'll find server-side script option

BR,

Leo

denizkaradal November 11, 2020

@LeoAnother try but no luck again. Here what I have done so far after your suggestion. In the "Mappings" section, the project was set along with "Bug" issue type(check pls my first picture). The group in which the users are has been also added into "Extern" and "Users" role.

1hmdl2.png

2 hmdl.JPG

What is the missing piece in here?

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 11, 2020

How about adjusting mappings by removing Bug issue type and keeping only Project value?

denizkaradal November 11, 2020

I tried but again no luck. I needed to select at least either "one issue type" or "all issue types". If not, I am not allowed to create a mapping. With"all issue types" did not function either.

In contrary, I realised that there is already a behaviour created for "Bug" issue type in this project but it only sets some text in "Description" by using "Initialiser".

What I have done: I deleted my behaviour and added my script as server side script into this existing behaviour but again no luck.

Any idea?

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 12, 2020

humm, have no idea why it is behaving like the you described. maybe someone can answer here

Feride Sena January 4, 2022

Hi @denizkaradal ,

Did you try to match your behaviour with your workflow? Please select your related project workflow from the "Guide workflow" field

Suggest an answer

Log in or Sign up to answer