Example Groovy script to update Object Type attribute value

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

目的

The example Groovy script in this documentation allows to update object attributes with non-Object type attribute types, for example, Text type. In order to update an attribute of type Object type, the object key has to be used. 

ソリューション

Here's an example code snippet to reference an object with key "ITSM-2" to a Host object.

import com.atlassian.jira.component.ComponentAccessor;

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 objectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(159).createMutable() //The id of the attribute

/* Create the new attribute bean based on the value */
def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(object, objectTypeAttributeBean, "ITSM-2");
/* Load the attribute bean */
def objectAttributeBean = objectFacade.loadObjectAttributeBean(object.getId(), objectTypeAttributeBean.getId());
if (objectAttributeBean != null)

{ /* If attribute exist reuse the old id for the new attribute */ newObjectAttributeBean.setId(objectAttributeBean.getId()); }
/* Store the object attribute into Insight. */
try

{ objectTypeAttributeBean = objectFacade.storeObjectAttributeBean(newObjectAttributeBean); }
catch (Exception vie) {
log.warn("Could not update object attribute due to validation exception:" + vie.getMessage());




説明Example Groovy script to update Object type attribute
製品Jira Service Management, Insight - Asset Management
最終更新日 2021 年 8 月 12 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.