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
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.
Thank you Marcos,
The return of this code is also "Anonymous".
Regards,
Anna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Could you please manually check that the component has a lead?
Where are you using this code?
Regards,
Marcos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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).
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi!
The problem was the Search template. When I change it to "User Picker Searcher" both codes work ok.
Thank you,
Anna
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It has sense!
Great to hear that it's working.
Have a nice day,
Marcos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.