ScriptRunner - Conditional Validator For Specific Group and Issue Type

Ricky Wang Lin June 30, 2022

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.
June 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.

 

Ricky Wang Lin July 2, 2022

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.
July 2, 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