groovy script to set the assignee from userpicker field on create transition

Hello everyone.

I'm trying to create a script  in a "create" postfunction to get an userpicker customfield value and with that value fill the assignee field.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def cf1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Nombre BR").toString()
issue.setAssignee(ComponentAccessor.getUserManager().getUserByName(cf1))

the code doesn't have any error but When I trying to create the issue. It doesn't nothing.

Also I tried put it in another transition after the issue creation. Same result.

The script execution doesn't have any error.


Is my code ok? 

Thanks in advance.

Cheers

1 answer

1 accepted

Hello Sergio.

Your code looks alright, you are going to have to look at the JIRA logs for this.

Beforehand, put this in your script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

def cf1 = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Nombre BR").toString()
log.debug("THE FIELD HAS THIS VALUE: {$cf1}")
def user = ComponentAccessor.getUserManager().getUserByName(cf1)
log.debug("THE USER WOULD BE {$user}")
issue.setAssignee(user)

With this, you will see those lines within your JIRA log, and you will be able to see wether your variables are right or not.

Maybe you will already see something in your logs like an null exception or something like that because the username is incorrect. Not sure.

Regarding debugging postfunctions, you could try them for a particular issue in your script console, in this article you will find an answer by Jamie Echlin, the creator of Scriptrunner describing how to do some debugging. 

I hope you found this useful, good luck debugging!

Cheers!

DYelamos

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Wednesday in Opsgenie

Getting the Most out of Atlassian and Opsgenie Together

We’re excited to invite you to this action-packed webinar where we will demonstrate how to integrate Opsgenie’s powerful alerting and on-call management tools with your entire Atlassian stack. Mar...

59 views 0 0
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