Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove mandatory concatenation character from Asset import?

Dhananjay Kale November 21, 2023

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

1 answer

1 accepted

0 votes
Answer accepted
Dhananjay Kale November 28, 2023

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

 

https://community.atlassian.com/t5/Jira-Service-Management-articles/Groovy-script-to-remove-default-concatenator-after-importing/ba-p/1782832

 

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());
}

Suggest an answer

Log in or Sign up to answer