Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Restricting to a Single Issue Type by Scriptrunner Behaviours

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 Nov 09, 2020 • edited

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

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 Nov 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 

@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 Nov 10, 2020

below screen shot may give you some idea

 

behaviour-field-selection.png

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 Nov 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

@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 Nov 11, 2020

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

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 Nov 12, 2020

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira

Announcing the waitlist for Jira Work Management

Hey there Cloud Community members! We’re excited to give you the first glimpse of the new home for business teams on Jira — Jira Work Management. Jira Work Management is the next generation of J...

750 views 12 19
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you