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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

197 views 2 11
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