Assign an issue in the post functions based on the values entered in field Labels

Stéphane Eursels August 22, 2017

Hi,

I'm totally newbie with Jira and so with JQL Query, groovy script and ScriptRunner.

I'm looking for a script to change the assignment, in the Post Functions of a transition, based on the values entered in another field of the issue.

In fact all of my issue have a multivalues field name's "Labels" and I want that when the user send the issue to the step of "reviewer" the assignee is automaticly change by Usr1 if the field Labels contain "RUN" or Usr2 if the field Labels contain "CHANGE".

I have installed ScriptRunner for test and I tried to adapt several examples found on the web but I have a lot of errors that I do not master.

Can anyone help me ?

Regards

3 answers

1 accepted

0 votes
Answer accepted
Stéphane Eursels August 23, 2017

Finally I found via several examples and a lot of test the way to do what I want.

I post my solution here if someone have the same requirement.

def containsLabel = "CHANGE" in issue.getLabels()*.label
if ( containsLabel ) {
    issue.setAssigneeId('sophie')
} else {
    containsLabel = "RUN" in issue.getLabels()*.label
    if ( containsLabel ) {
        issue.setAssigneeId('daniel')
 } else {
     issue.setAssignee(null)
    }
}
0 votes
Stéphane Eursels August 22, 2017

I have try this script in script custom on post functions of my transition, it generated no error when saving.

import com.atlassian.jira.component.ComponentAccessor

//Grab necessary Components
def cfm = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()

//Set custom text field
def cfLabels = cfm.getCustomFieldObjectByName("Labels")

def cVal = issue.getCustomFieldValue(cfLabels)

if( cVal in "RUN" ) {
issue.setAssigneeId('daniel')
}else{
issue.setAssigneeId('sophie')
}

But when I use the transition it doesn't work and I have this error in the logs :

2017-08-22 17:03:13,776 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-08-22 17:03:13,807 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: ITINV-211, actionId: 281, file: <inline script>
java.lang.NullPointerException
 at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
 at com.atlassian.jira.issue.Issue$getCustomFieldValue$2.call(Unknown Source)
 at Script262.run(Script262.groovy:10)

Can anyone help me ?

Thanks.

0 votes
Stéphane Eursels August 22, 2017

I have test this solution without error when saving :

import com.atlassian.jira.component.ComponentAccessor

//Grab necessary Components
def cfm = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()

//Set custom text field
def cfLabels = cfm.getCustomFieldObjectByName("Labels")

def cVal = issue.getCustomFieldValue(cfLabels)

if( cVal in "RUN" ) {
issue.setAssigneeId('laurent')
}else{
issue.setAssigneeId('sophie')
}

But it doesn't work, the assignee doesn't change and i have the error in log :

2017-08-22 17:03:13,776 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-08-22 17:03:13,807 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: ITINV-211, actionId: 281, file: <inline script>
java.lang.NullPointerException
 at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
 at com.atlassian.jira.issue.Issue$getCustomFieldValue$2.call(Unknown Source)
 at Script262.run(Script262.groovy:10)

 Thanks for any help.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events