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 been struggling for a week to figure out why i cant get this script to work.
i have 2 customfields, one with a system list, and one with an employee list.
If a system is choosen i want to autopopulate the employee list with the system approvers that is added for the system, and also be able to add more users.
My script so far. ( i'm not a coder, bear with me)
I have several pointers:
1) it is best practice in java and groovy to reserve the initial cap for class names. Instances of those classes or any other variables should start with a lowercase.
So
@PluginModule ObjectTypeAttributeFacade objectTypeAttributeFacade
//and
def systemApprover = 'System approver'
Rather than
@PluginModule ObjectTypeAttributeFacade ObjectTypeAttributeFacade
//and
def SystemApprover = 'System approver'
2) Don't confuse CustomFields and FormFields. In behaviours, we interact with formFields. In postFunctions and listeners, we interact with CustomFields
3) You have a few other issues with either missing quotes around strings or calling invalid methods (objectAttributeBeans vs objectAttributeBean).
4) I'm assuming your System approver insight attribute is a "Jira User" type. This attribute stores the "User Key". Which may be something like JIRAUSER1234. But behavior needs to specify the User Name for a user picker field.
Try this .... it should work, or at least be close:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
import groovy.transform.BaseScript
@WithPlugin('com.riadalabs.jira.plugins.insight')
@BaseScript FieldBehaviours fieldBehaviours
@PluginModule ObjectFacade objectFacade
@PluginModule ObjectTypeAttributeFacade objectTypeAttributeFacade
// systemchoice customfield_12800
// approver customfield_12803
def systemFld = getFieldById('customfield_12800')
def approverFld = getFieldById('customfield_12803')
//in my experience, there are time when behaviour returns a list of object key, while others just the single value.
def systemFldValue = systemFld.value
if (systemFldValue instanceof List) {
systemFldValue = systemFldValue[0]
}
//get an object bean for the selected system
def systemObject = objectFacade.loadObjectBean(systemFldValue as String) as ObjectBean
//get the System approver value from the System object
def systemApproverAttName = 'System approver'
def approverAttribute = objectTypeAttributeFacade.loadObjectTypeAttribute(systemObject.objectTypeId, systemApproverAttName)
def systemObjApproverAttr = systemObject.objectAttributeBeans.find { it.objectTypeAttributeId == approverAttribute.id }
def approverUsers = systemObjApproverAttr.objectAttributeValueBeans.collect { ComponentAccessor.userManager.getUserByKey(it.value as String) }
// Set approver with 'system approver'
approverFld.setFormValue(approverUsers*.name)
log.warn(Approver: approverUsers)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.