How to get project role using simple script to validate in transition ?

SUHAS BHUJBAL September 19, 2019

Hello team,

 

I have added one validation for one field while creating the Issue (issue type = Bug).

 

if ((issue.issueTypeObject.name == 'Bug') && !cfValues['Regression Bug']) {
return false;
} else {
if (cfValues['Regression Bug']?.value == 'Could not be checked' && !cfValues['Regression Bug Comment']) {
return false;
}

return true;
}

 

Now for one another field I need to check the user is developer and field value is "NOT SET" otherwise return false. 

I will add this code in simple scripted validator.

Please help me with this.

 

Thanks

Suhas

1 answer

1 vote
Zoi Raskou
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.
September 19, 2019

Hello Suhas, 

To find the project role you can use the following: 

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

def projectManager = ComponentAccessor.projectManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def allProjects = projectManager.getProjects()
def project = allProjects.find(){it.getName() == "Project Name"}

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def projectRoles = projectRoleManager.getProjectRoles(user, project)
def memberOf = projectRoles.find(){it.getName() == "Developer"}?true:false

if (memberOf){
*Do stuff*

}

 

I am not sure what you mean with field value is not set. Is it a select field with the option "NOT SET" or is it null?

SUHAS BHUJBAL September 20, 2019

Yes, its a field with value "NOT SET".

So you saying the above code will work in simple scripted validator?

SUHAS BHUJBAL September 20, 2019

Hi Raskou

I have achieved this using following:

if ((isUserMemberOfRole('Developers')) && cfValues['Management Flag']!= 'NOT SET') {
return false;

}

return true;

Thanks for your help!

Regards,

Suhas

Zoi Raskou
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.
September 24, 2019

Hello Suhas, 

That's great, glad you got it working!

Suggest an answer

Log in or Sign up to answer