Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Condition Code for validation is not working

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
Hana Kučerová Community Leader Dec 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.

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
}

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,022 views 8 28
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you