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
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...

76 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