Assign to first member of role groovy script modification

I need to modify the Assign to first member of role built-in script so that if there are no users is the said role it moves on to the next status in the workflow.

Regards,

Jenin C M

2 answers

1 accepted

4 votes
Henning Tietgens Community Champion Feb 19, 2014

Ok, example.

Status A -> Transition to B -> Status B -> Transition to C -> Status C

You are talking about Transition to B. There is a postfunction "Assign to first member of role", lets say you configured role R.

If there is no member in role R, the issue "Transition to B" takes place without changing the assignee. The issue is in Status B.

I suspect "Move it to the next status" should mean Transition to C, correct?

In this case you have to add another script postfunction "Fast-track transition an issue" and add this condition to it.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)

def projectRoleId = 10000  // ID of project role
def role = projectRoleManager.getProjectRole(projectRoleId)
def actors = projectRoleManager.getProjectRoleActors(role, issue.projectObject)
!(actors.users)

Replace the projectRoleId with the ID of the corresponding role and choose the correct action for "Transition to C".

I think if you can get the source code of "Fast-track transition an issue" script and then modify it to check the roles. Do not start with "Assign to first member of role" script.

The reason is, "Fast-track transition an issue" script is the one that performs the required action. You need "Assign to first member of role" script only to understand how the validation (check the role members) should be done.

So start with "Fast-track transition an issue". Copy some code from "Assign to first member of role" into it. Good luck! :)

1 votes
Henning Tietgens Community Champion Feb 19, 2014

Mmh. This is not a question.

If you want to modify a builtin script, you can copy the source (through the provided source link in the script) and save it with a modified name to the path (under WEB-INF/classes) according to the package of the script (which should not be changed).

This new script can now be adapted by you to your needs.

I need help with modifying the script. I am not good with scripting.

Henning Tietgens Community Champion Feb 19, 2014

Mmh, I took a look into the script. If there is no user in a role nothing happens, only a warning message is logged to the log file. So the transition should happen.

Is that what you want? Or is "the next status" another transition after this transition?

I need to move it to the next status if there is no user in a role.

Regards

Jenin

Still not able to achieve it, its still going to transition B eventhough the condition is not met: I have added both post functions as given below:

  1. Script workflow function : Assign this issue to the first member of the Second Approver role
  2. Script workflow function : Fast-track transition an issue : If the condition is met the action 791 Approve will be applied.
    Note that this should go after the Fire Event function.

Henning Tietgens Community Champion Feb 20, 2014

Did you add the Fast-track transition an issue postfunction after the fire event postfunction?

I am bit confused here, what would be fire event postfunction?

Got it!!! Thanks a ton Henning!!! Much appreciated!! A big tick mark for your help!!

Regards

Jenin

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,760 views 11 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot