Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script field - Show component lead

Anna Protopapa
Contributor
April 24, 2018

Hello,

We need to have a field with the componet lead. We used the code from adaptavist samples but we need some help to return the application user.

Can anybody help us?

package com.onresolve.jira.groovy.test.scriptfields.scripts
import com.atlassian.jira.user.ApplicationUsers
import com.atlassian.jira.ComponentManager
def components = issue.componentObjects.toList()
if (components) {
  def lead = components?.first()?.componentLead.getDirectoryUser()
  return ApplicationUsers(lead)
}

Thank you

1 answer

1 accepted

1 vote
Answer accepted
Marcos Sanchez
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 24, 2018

Hi,

Try this code to get the ApplicationUser for the component lead:

import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.userManager

def components = issue.componentObjects.toList()

if (components) {
  def lead = components?.first()?.componentLead.getDirectoryUser()
  def leadUser = userManager.getUser(lead.name)
return leadUser

}

This code returns the ApplicationUser object.

You can get the username or the full name replacing this

def leadUser = userManager.getUser(lead.name)
return leadUser

with this to return the username:

return lead.name  

or with this to return the full name:

return lead.displayName

 

Regards,
Marcos.

Anna Protopapa
Contributor
April 24, 2018

Thank you Marcos,

The return of this code is also "Anonymous".

Regards,

Anna

Marcos Sanchez
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 24, 2018

Hi,

Could you please manually check that the component has a lead?

Where are you using this code? 

Regards,
Marcos

Anna Protopapa
Contributor
April 24, 2018

Hi,

Yes it has a lead. I am using it in a script field and I see the Anonymous as a result on the preview button.

Regards,

Anna

Marcos Sanchez
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 24, 2018

Hi,

I just tried it in a script field and it's working fine to me (as you can see in the screenshot, using the user msanchezg as component lead).

2018-04-24_15h34_55.png

I'm not sure about what could be happening to you...

Try putting a 

return components

before the if(components) and lets see the response, maybe we can get something from there.

 

Regards,
Marcos

Anna Protopapa
Contributor
April 24, 2018

Hi!

The problem was the Search template. When I change it to "User Picker Searcher" both codes work ok.

Thank you,

Anna

Marcos Sanchez
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 24, 2018

It has sense!

Great to hear that it's working.

 

Have a nice day,

Marcos

Suggest an answer

Log in or Sign up to answer