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,554,036
Community Members
 
Community Events
184
Community Groups

How to get attribut for multi-select-user-field with groovy

I want to use Groovy in a post-function to get the approver from a custom field of the type Multi-User-Select and then read a specific attribute from Insight, where the approver is stored as an object.

The script I have does not work. It only works if the user is read from an Assets-Objects field.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade")
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass)

CustomField u = customFieldManager.getCustomFieldObject(10406)
ArrayList myValue = issue.getCustomFieldValue(u) as ArrayList
ArrayList myAttributes = []
return myValue
myValue.each {
def myAttrValue = objectFacade.loadObjectAttributeBean(it.getId(), 7201).getObjectAttributeValueBeans()[0].getValue()
myAttributes.add(myAttrValue)
}

 

1 answer

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 19, 2023

Presumably, your user object type in Insight has an attribute of type Jira User. Or at least a user name or something else that we can use to find the user based on the selected users in the user picker.

So you should be able to use the iqlFacade to search for the user object and then retrieve the attributes that way.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade

CustomFieldManager customFieldManager = ComponentAccessor.customFieldManager
@WithPlugin('com.riadalabs.jira.plugins.insight') insightPlugin
@PluginModule ObjectFacade objectFacade
@PluginModule IQLFacade iqlFacade
issue = issue as Issue
CustomField approversCf = customFieldManager.getCustomFieldObject(10406)
List<ApplicationUser> selectedApprovers = issue.getCustomFieldValue(approversCf) as List<ApplicationUser>

def assetAttributes = selectedApprovers.findResults {user->
def userObjectList = iqlFacade.findObjects("""objectType = "Your user Object" and "Jira Account" = $user.key """)
if(!userObjectList) {
log.warn "Unable to find user object using $user"
return null
}
def userObject = userObjectList[0]
objectFacade.loadObjectAttributeBean(userObject.id, 7201).objectAttributeValueBeans*.value[0]
}

return assetAttributes

I also added a couple of groovy/scriptrunner shortcuts.

I don't use/have ScriptRunner installed. Are there any options without scriptrunner shortcuts?

The user(s) is stored in my custom field 10406 in the following format:

[fisrtname.lastname@company.com(firstname.lastname@company.com)]
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 21, 2023

Sorry, I missed that fact (about not having scriptrunner).

Here is a version without scriptrunner shortcuts:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade

CustomFieldManager customFieldManager = ComponentAccessor.customFieldManager
ObjectFacade objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ObjectFacade)
IQLFacade iqlFacade = ComponentAccessor.getOSGiComponentInstanceOfType(IQLFacade)
issue = issue as Issue
CustomField approversCf = customFieldManager.getCustomFieldObject(10406)
List<ApplicationUser> selectedApprovers = issue.getCustomFieldValue(approversCf) as List<ApplicationUser>

def assetAttributes = selectedApprovers.findResults { user ->
def userObjectList = iqlFacade.findObjects("""objectType = "Your user Object" and "Jira Account" = $user.key """)
if (!userObjectList) {
log.warn "Unable to find user object using $user"
return null
}
def userObject = userObjectList[0]
objectFacade.loadObjectAttributeBean(userObject.id, 7201).objectAttributeValueBeans*.value[0]
}

return assetAttributes

Be sure to update the IQL to the correct attribute name from your insight object that matches with either the user's name or user's key. In my example, I used "Jira Account" yours might be different.

Like Pythagoras likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events