Hi! I write "then" script for Asset Automation. I need paste second and third attribute values for all objects where first field value equals first field from object.
But object and foundObjects have type LegacyObjectBean instead of ObjectBean and doesn't have method createObjectAttributeBeanForObject. I tried from foundObject getting MutableObjectBean but i don't found how update attribute value too. Below is my script:
import com.atlassian.jira.component.ComponentAccessor
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade
import com.riadalabs.jira.plugins.insight.services.model.ObjectBean
import com.riadalabs.jira.plugins.insight.services.model.factory.ObjectAttributeBeanFactory
import com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade
import com.riadalabs.jira.plugins.insight.services.model.ObjectAttributeValueBean
import com.riadalabs.jira.plugins.insight.services.model.ObjectAttributeBean
IQLFacade iqlFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.IQLFacade"))
ObjectFacade objectFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectFacade"));
ObjectTypeAttributeFacade objectTypeAttributeFacade = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.channel.external.api.facade.ObjectTypeAttributeFacade"));
ObjectAttributeBeanFactory objectAttributeBeanFactory = ComponentAccessor.getOSGiComponentInstanceOfType(ComponentAccessor.getPluginAccessor().getClassLoader().findClass("com.riadalabs.jira.plugins.insight.services.model.factory.ObjectAttributeBeanFactory"));
def firstAttributeId = 1
def secondAttributeId = 2
def thirdAttributeId = 3
def firstValue = objectFacade.loadObjectAttributeBean(object.id, firstAttributeId)?.getObjectAttributeValueBeans()?.get(0)?.getValue()
def objectSchemaId = 1
def query = "objectType = \"Fields\" AND \"First field\" = \"$firstValue\""
def foundObjects = iqlFacade.findObjects(objectSchemaId, query) as List<ObjectBean>
def secondObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(secondAttributeId).createMutable()
def thirdObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(thirdAttributeId).createMutable()
def secondValue = objectFacade.loadObjectAttributeBean(object.id, secondAttributeId)?.getObjectAttributeValueBeans()?.get(0)?.getValue()
def thirdValue = objectFacade.loadObjectAttributeBean(object.id, thirdAttributeId)?.getObjectAttributeValueBeans()?.get(0)?.getValue()
foundObjects.each { foundObject ->
def newAssetObjectAttributeBean1 = objectAttributeBeanFactory.createObjectAttributeBeanForObject(foundObject, secondObjectTypeAttributeBean, secondValue);
def newAssetObjectAttributeBean2 = objectAttributeBeanFactory.createObjectAttributeBeanForObject(foundObject, thirdObjectTypeAttributeBean, thirdValue);
objectFacade.storeObjectAttributeBean(newAssetObjectAttributeBean1)
objectFacade.storeObjectAttributeBean(newAssetObjectAttributeBean2)
}
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.