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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

ScriptRunner - Conditional Validator For Specific Group and Issue Type

Can anyone advice me on how I can use ScriptRunner's built-in script to make it so that:

  • If issue type = Bug, then only users in group = "Security" can create the ticket without issues.
  • If issue type = Bug, users NOT in group = "Security" attempting to create the ticket will not advance and display error message "You need to be in Security group in order to create this ticket"

I have a scripted Behaviour already, but want to enforce it with a validator to make sure no one else accidentally get to create a Bug ticket (per guidance from here: https://docs.adaptavist.com/sr4js/6.33.0/features/behaviours/behaviours-examples/restricting-issue-types)

All other documentations on the ScriptRunner KB doesn't cover this specific scenarios.  Any thoughts would be appreciate it.  Thank you!

1 answer

Suggest an answer

Log in or Sign up to answer
2 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jun 30, 2022

A "simple scripted validator" on your create transition can accomplish that.

import com.atlassian.jira.component.ComponentAccessor
ComponentAccessor.groupManager.isUserInGroup(currentUser, 'Security')

Note: currentUser is already defined in a simple scripted validator.

And the last line will return true/false. If it returns false, the validator fails and the message you specify in the "Error Message" field will be displayed.

 

Hi Peter.  Thanks for providing an insight on this.  Is it possible for the script to only conditionally target a specific issue type?

Basically, I have 1 workflow behind 2 issue types (Say Bug and Task) and I only want this logic to apply to issue type Bug, and Task remains open for anyone to use.

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jul 02, 2022

sure... that's quite simple:

import com.atlassian.jira.component.ComponentAccessor
def restrictedIssueTypes = ['Bug', 'Defect']
if(!restrictedIssueTypes.contains(issue.issueType.name)){
return true
}

ComponentAccessor
.groupManager.isUserInGroup(currentUser, 'Security')

Like Ash likes this
TAGS
AUG Leaders

Atlassian Community Events