You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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)
}
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)]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.