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

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

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)
    }
}

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.

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.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

85 views 0 5
Read article

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