Forums

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

Insight : How add multiple values from Insight object to another inside object attribute in groovy?

Julian from AF
Contributor
October 2, 2020 edited

Hello,

 

i'm trying to find the good way to add or append a value to an attribute with multiple value capable but i don't found the good way. I can add just one value without any issue but 2 values or more i don't found the good way.

Normally you need to add all new value for each attribute to one var list with new value for each one but how to do for many value for one attribute for machineSNCFValue ? 

 

THank you !

 

CustomField customerNameCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12829);
customerNameCFValue = issue.getCustomFieldValue(customerNameCF);

CustomField customerSiteCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12830);
customerSiteCFValue = issue.getCustomFieldValue(customerSiteCF);

CustomField customerCountryCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12831);
customerCountryCFValue = issue.getCustomFieldValue(customerCountryCF);

CustomField machineSNCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12832);
machineSNCFValue = issue.getCustomFieldValue(machineSNCF);

CustomField pinCodeCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12834);
pinCodeCFValue = issue.getCustomFieldValue(pinCodeCF);

CustomField pukCodeCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12836);
String pukCodeCFValue = issue.getCustomFieldValue(pukCodeCF);

CustomField simproviderCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12837);
String simproviderCFValue = issue.getCustomFieldValue(simproviderCF);

CustomField componentCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(12340);
componentCFValue = issue.getCustomFieldValue(componentCF);
log.warn("componentCFValue: " + componentCFValue)

def newValues = [customerNameCFValue,machineSNCFValue,pinCodeCFValue,pukCodeCFValue,simproviderCFValue,customerCountryCFValue,secureconnector,raspberry]
def attributeList = [48337,48300,48276,48275,48272,48354,48355,48356]
//Name, Customer, Machine , Pin Code, Puk Code, Country, components to deploy
def objectTypeSecureConnector = objectTypeFacade.loadObjectTypeBean(2503); //Get ObjectTypeID
def newObjectBean = objectTypeSecureConnector.createMutableObjectBean(); /* Create a new unsaved object bean */
def objectAttributeBeans = new ArrayList(); /* Set up the attribute list */
//add new name in attribute bean BEGIN
def nameObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(48260);
objectAttributeBeans.add(objectAttributeBeanFactory.createObjectAttributeBeanForObject(newObjectBean, nameObjectTypeAttributeBean, newName))
//add new name in attribute bean END

n = 0
(attributeList).each {
currentAttribute = attributeList[n]
currentValue = newValues[n]
test = currentValue
//log.warn("Object avant converstion en string: " + test)
//log.warn("Class avant converstion en string: " + test.getClass())
testStr = test.toString()
//log.warn("Test du field si une parenthèse est détecté: " + testStr)
result = (testStr.contains(")"))
if (result == true){
log.warn("Considéré comme object Insight : " + currentValue[0])
mt_split(currentValue)
currentValue = mt_split_value
}

//log.warn("result" + result)
nameObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(currentAttribute);

.add(objectAttributeBeanFactory.createObjectAttributeBeanForObject(newObjectBean, nameObjectTypeAttributeBean, currentValue))
log.warn("attributeList" + currentAttribute)
log.warn("Value injected = " + currentValue)

n++
}
newObjectBean.setObjectAttributeBeans(objectAttributeBeans);
try {
//newObjectBean = objectFacade.storeObjectBean(newObjectBean);
log.warn("newObjectBean: " + newObjectBean);
} catch (Exception vie) {
log.warn("Could not create issue due to validation exception:" + vie.getMessage());
}

 

 

2020-10-02 09_47_12-Edit Issue _ IT-8134 - AF Jira.png 2020-10-02 09_30_28-Insight - AF Jira.png

0 answers

Suggest an answer

Log in or Sign up to answer