Condition Code for validation is not working

Jason Li Ting Chung December 17, 2020

Hi Teams,

I am trying to put a validation where a reporter needed to be in the role of say "Business Nominee" to be able to create an issue. I have try the following code but it is not working:

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

def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
projectRoleManager.isUserInProjectRole(issue.reporter?.name, "Business Nominee")

Could I have some support?

Thank you in advance.


Best regards,
Jason Li

3 answers

0 votes
Graham Twine _Slm_ December 17, 2020

Hi @Jason Li Ting Chung I am assuming you have scriptrunner installed as you are writing groovy scripts.

 

Have a look at Advanced workflow configurations here.

It may be worth understanding the difference between conditions and validations.
What you are trying to achieve can be done out the box in Jira workflow configurations and Adaptavast adds a few more features to this.

0 votes
Subrat Mishra
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 17, 2020

Hi @Jason Li Ting Chung  Please try below code.

 

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

def projectManager = ComponentAccessor.projectManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def user = issue.getReporter()

def project = issue.getProjectObject()

def projectRoles = projectRoleManager.getProjectRoles(user, project)
if(projectRoles.find(){it.getName() == "Business Nominee"}){
return true
}
0 votes
Hana Kučerová
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 17, 2020

Hi @Jason Li Ting Chung ,

why do you need this to be a groovy script?

You should be able to handle this request using OOB Jira functionality easily.

You can add Permission validator "Only users with Create Issues permission can execute this transition." on the create transition and then update your permission scheme and set only "Business Nominee" project role has the Create Issues permission.

Suggest an answer

Log in or Sign up to answer