There is an Insight Object Schema with three Object Types viz:
The employee data is being populated from LDAP with attributes like Name and Sub-Bu. However, the BU is not populated, since there is no reference in the LDAP. This needs to be updated within Insight i.e. Employee Objects, by checking the Sub-Bu assigned to each Employee and checking for the linked Parent BU and updating it. PFA Image.
I am using the Insight Automation - with execute script when Objects updated. And the script is as attached. Any help would be much appreciated!
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
...
// Classes imports
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
Class objectFacadeClass = ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.web.api.facade.ObjectFacade")
objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(objectFacadeClass)
customFieldManager = ComponentAccessor.getCustomFieldManager()
componentManager = ComponentManager.getInstance()
// Insight variables
def objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade"))
def objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade"))
def objectAttributeBeanFactory = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.services.model.factory.ObjectAttributeBeanFactory"))
def iqlFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade"))
// New attribute to be populated
def assetAttributeName = "BU"
// Object Type
def ownerAttributeName = "Sub BU"
// Related objects and their object type id's
def assetObject = object
//def iql = "objectType=\"Sub Business Unit\" AND object HAVING inR(Key = EST-"+assetObject.getId()+")"
def iql = "objectType = \"Business Unit\" and object having outboundReferences(Key = EST-"+assetObject.getId()+")"
// 5= Object Schema ID of employee
def ownerObject = iqlFacade.findObjectsByIQLAndSchema(5, iql)[0]
int assetObjectTypeId = assetObject.getObjectTypeId()
int ownerObjectTypeId = ownerObject.getObjectTypeId()
// Owner object type attribute bean (Network Interface of the Object Type)
def ownerObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(ownerObjectTypeId, ownerAttributeName)
// Owner object attribute bean (Network Interface of the owner object)
def ownerObjectAttributeBean = objectFacade.loadObjectAttributeBean(ownerObject.getId(), ownerObjectTypeAttributeBean.getId())
// Getting the value of the owner attribute (Network Interface value)
def ownerObjectAttributeValue = ownerObjectAttributeBean.getObjectAttributeValueBeans()[0].getValue()
// Asset object type attribute bean (Network Interface of the Object Type)
def assetObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(assetObjectTypeId, assetAttributeName)
// Creating a new value for the attribute in the Asset object (New Network Interface value of the Asset)
// Change 'EST' to your Object Schema Key
def newAssetObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(assetObject, assetObjectTypeAttributeBean, "EST-"+ownerObjectAttributeValue)
// Store the object attribute into Insight
try {
assetObjectTypeAttributeBean = objectFacade.storeObjectAttributeBean(newAssetObjectAttributeBean)
} catch (Exception vie) {
log.warn("Could not update object attribute due to validation exception:" + vie.getMessage())
}
/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.