Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Using ScriptRunner to Create Workflow Validator by User

Darron June 3, 2021

Hello -

New to ScriptRunner, so bare with me!

Problem: I want to implement "advanced" security that will restrict users from creating a ticket under certain factors..

  • Factor 1: the user must be provisioned to create issues in the system.
  • Factor 2: If the user is attempting to enter a value for Priority on creation of issue, then they must be apart of a Power User group.  
  • Factor 3: If the user not attempting to enter a value for Priority on creation of issue, then they will be allowed to create issue as long as they meet the criteria for Factor 1.

Solution: I thought I may be able to use Workflow and ScriptRunner to implement this.

Implementation: In my workflow, I have the following:

  • Added a validator for the Create transition
  • Validator 1: Only users with Create Issues permission can execute this transition.
  • Validator 2: Script Runner Script

Validator 2 is where I am "stuck" at and need some assistance. I've been looking at guides at what logic to write, but am having trouble piecing together Jira Expressions. None of the examples show if/else logic, so not sure if I can do that with these validators?  Can anyone point me in the right direction? 

1 answer

1 accepted

0 votes
Answer accepted
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
June 3, 2021

Hi @Darron . How do you want to make Priority field optional? Is it your custom field?

But expression for user + group should be

user.groups.includes("Power User")

If you will clarify the priority "issue", we can complete it :) 

Darron June 3, 2021

Hi @Martin Bayer _MoroSystems_ s_r_o__ 

Priority is the out of the box field available from JIRA Cloud. It is already set up as optional (by default), and from my understanding that cannot be changed.

 

Is it possible to achieve what I am trying to do with the out of the box Priority field? Or do I need to use a custom field instead?

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
June 4, 2021

I just tested it. The true is that Priority is not marked as optional but I can not fill in the blank option. Can you share your Create screen?

Darron June 4, 2021

ahh, I see what you're saying. 

Yes, Priority cannot be blank. On issue create, our Priority value is set to Unprioritized. 

 

JIRA Priority.png

Darron June 4, 2021

Therefore the factors change a bit...

  • Factor 1: the user must be provisioned to create issues in the system.
  • Factor 2: If the user is attempting to enter a value other than Unprioritized for Priority on creation of issue, then they must be apart of a Power User group.  
  • Factor 3: If the user not attempting to enter a value other than Unprioritized for Priority on creation of issue, then they will be allowed to create issue as long as they meet the criteria for Factor 1.
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
June 6, 2021

Hi @Darron I think this Jira Expression should work:

(user.groups.includes("Power User") && issue.priority.name != 'Unprioritized') || issue.priority.name == 'Unprioritized'
Darron June 7, 2021

Thanks @Martin Bayer _MoroSystems_ s_r_o__ . 

I tested this out and worked perfectly. With this as a baseline, I should be able to figure out anything else I need. Really appreciate your help. 

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
June 8, 2021

You're welcome :) Happy to help :)

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, likes for trees, atlassian community, social impact, tree planting campaign, community kudos, atlassian giving, environmental impact, sustainability, likes for good, atlassian social responsibility, community challenge

Make every click count—help us plant 50,000 trees! 🌳

Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!

Help us plant more trees
AUG Leaders

Atlassian Community Events