Scripted field to show Component Lead

Jordan Packer April 1, 2015

I'm trying to create a scripted field (using the Script Runner Plugin) that will show the component lead for the component selected on a given issue. According to the documentation, this is the way to do that:

import com.atlassian.jira.ComponentManager
 
def componentManager = ComponentManager.getInstance()
 
def issue = componentManager.getIssueManager().getIssueObject("JRA-1025")
 
def leads = issue.componentObjects.toList()
if (leads) {
    def lead = leads?.first()?.lead
    if (lead) {
        componentManager.getUserUtil().getUser(lead)
    }
}

However, whenever I try this (inputting an appropriate issue key for my JIRA instance), the result just comes back as "Anonymous" every time. Has something changed since the documentation was written? What would be the best way to do this?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
JamieA
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.
April 2, 2015

It's to do with the different types of user object in jira. Try:

componentManager.getUserUtil().getUserByKey(lead)

This will give you an ApplicationUser, which is what the template expects.

 

Jordan Packer April 2, 2015

That was the trick, thank you so much Jamie!

Daniel Luevano August 13, 2015

What change do I need if I want to apply this on the create form? Since there is not Issue Number?

JamieA
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.
August 18, 2015

Are you asking about behaviours or script fields? A new question is probably warranted judging by your deleted comment.

Daniel Luevano August 18, 2015

Currently I was able to apply it with behaviours but I wanted to do it on script fields (Just to know)

JamieA
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.
August 18, 2015

you can't have a script field on the "create" form

TAGS
AUG Leaders

Atlassian Community Events