Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Sergio Palacio October 10, 2017

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

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Daniel Yelamos [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 16, 2017

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

TAGS
AUG Leaders

Atlassian Community Events