While importing objects in Assets, we have requirement that we need to concatenate two attributes in one.
"Customer"--> ABC
"Short Code"--> PQR
So "Customer Short Code" will be ABCPQR
But we have to provide mandatory concatenator character (e.g. hyphen - ) while import. When we try to import, it attaches hyphen (e.g. ABC-PQR) and we don't need that concatenator character. We just need to import without any concatenator (e.g. ABCPQR).
How to do it as we just need plain concatenation of two attributes?
-Dhananjay
OK. So this can be done with the help of groovy script mentioned on this page.
Note - You also need to add this script in Allowlist Configuration in Assets
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(161).createMutable() //The id of the attribute, found in the object type Attributes screen
def objectAttributeBean = objectFacade.loadObjectAttributeBean(object.getId(), objectTypeAttributeBean.getId());
def attrValue = objectAttributeBean.getObjectAttributeValueBeans()[0].getValue()
def containsSpace = attrValue.contains("-")
/* check if the attribute contains space inserted as a concatenator value, replace it with empty char */
if (containsSpace == true) {
attrValue = attrValue.replaceAll("-","")
}
/* debug value */
// log.warn("New value: " + attrValue)
/* Create the new attribute bean based on the value */
def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(object, objectTypeAttributeBean, attrValue);
/* Load the attribute bean */
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());
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.