need to add Script condition for project role on transition

Admin May 7, 2023

Hi All,

what should be the script for project role(like: Tester) condition on transition?

Means, only testers would be visible on particular transition.

I was trying this : isUserMemberOfRole('Testers') , but it's not working.

 

Thanks.

2 answers

1 accepted

1 vote
Answer accepted
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 8, 2023

Hi @Admin You are trying to set up a condition, users which are in Tester project role only have permission to transition this issue, right ? 

Instead of writing a scripted condition, you can this Condition Project role(s) condition [ScriptRunner] : Allows the transition if the current user is, or is not, a member of the specified project role(s).

Admin May 8, 2023

yes , this condition is working , but I want to try through writing the script i.e , inline script.

Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 8, 2023

@Admin  I think you are trying to add Custom Scripted Condition, for this try below script :- 

 

import com.atlassian.jira.component.ComponentAccessor

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

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def projectRoleManager = ComponentAccessor.getComponentOfType(com.atlassian.jira.security.roles.ProjectRoleManager)

def testerRole = projectRoleManager.getProjectRole("Tester")

def project = issue.getProjectObject()

def userInTesterRole = projectRoleManager.isUserInProjectRole(currentUser, testerRole, project)

log.warn userInTesterRole

passesCondition = userInTesterRole


Like Admin likes this
Admin May 8, 2023

yes its working , but could you please exlain the code step by step that will be  very clear understanding for me  or else we can able to write next condition or something  by ourself.

 

Thank You very much.

Like Vikrant Yadav likes this
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 8, 2023

@Admin  Glad to hear I am able to help you out! Kindly accept the solution, if works for you as it helps other users looking for same solution. 

Detailed Description :- 

import com.atlassian.jira.component.ComponentAccessor

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

//get Current User/logged in User
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

//get project roles
def projectRoleManager = ComponentAccessor.getComponentOfType(com.atlassian.jira.security.roles.ProjectRoleManager)

//get Tester roles from Project Roles
def
testerRole = projectRoleManager.getProjectRole("Tester")

//get Project Key
def
project = issue.getProjectObject()

//check if user in Tester project role or not, it gives true or false value and value stores in variable userInTesterRole 
def
userInTesterRole = projectRoleManager.isUserInProjectRole(currentUser, testerRole, project)

log.warn userInTesterRole

//pass condition if userInTesterRole  is true , fail if userInTesterRole  is false
passesCondition = userInTesterRole
Like # people like this
Admin May 8, 2023

@Vikrant Yadav Thanks a lot for your support.

Like Vikrant Yadav likes this
Vikrant Yadav
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 8, 2023

Hi @Admin kindly accept the solution.

0 votes
Sebastian Krzewiński
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 8, 2023

Hi @Admin 

 

Did you try to use 'User Is In Project Role' condition?

 

Regards,

Seba

Admin May 8, 2023

yes , I tried still not working

Suggest an answer

Log in or Sign up to answer