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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,512
Community Members
 
Community Events
176
Community Groups

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

1 vote
Answer 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
TAGS

Atlassian Community Events