To close a particular sub-task is user in project role

Jeff Foege December 20, 2021

I've tried several examples that I've found for Scriptrunner but can't seem to get something to work. I want to set a validator on a sub-task with "Code review" in the summary and a user is in a project role. Some of the code I found has  underlyingIssue in it but my jira doesn't seem to recognize it. I've tried this IF:

if (issue.getSummary().equals("Code review") && (groupManager.isUserInGroup(currentUser, "Dev Lead")))

and 

if (projectRoleManager.isUserInProjectRole(currentUser, devProjectRole, underlyingIssue.getProjectObject()))

I'm using Script Validator (Scriptrunner) and we are using Jira 8.1.0.

 

Thanks for your time!

~jeff

 

1 answer

0 votes
Adrien Low _ServiceRocket_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 24, 2021

Hey @Jeff Foege ,

Can you try changing underlyingIssue.getProjectObject() to issue.getProjectObject() instead?

I configured the script in my Validator and was able to get the error to appear if the user is not in the Administrator role:-

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

def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)

def adminRole = projectRoleManager.getProjectRole('Administrators')

if(issue.getSummary().equals("Code Review") && projectRoleManager.isUserInProjectRole(currentUser, adminRole, issue.getProjectObject())) {
return true
} else {
return false
}

Hope this helps.

Regards.

Suggest an answer

Log in or Sign up to answer