Assign to first member of role groovy script modification

Jenin CM February 19, 2014

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
Answer accepted
Henning Tietgens
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.
February 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".

Sameera Shaakunthala [inactive]
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.
February 19, 2014

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 vote
Henning Tietgens
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.
February 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.

Jenin CM February 19, 2014

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

Henning Tietgens
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.
February 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?

Jenin CM February 19, 2014

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

Regards

Jenin

Jenin CM February 20, 2014

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
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.
February 20, 2014

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

Jenin CM February 20, 2014

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

Jenin CM February 20, 2014

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

Regards

Jenin

Suggest an answer

Log in or Sign up to answer