Hi Community!
I want to update Insight object attribute in workflow post function. I have many object type e.g.: Monitor, Laptop, Phone. Every object type has the attribute: Status (The type of the Status attribute is Status). In the ticket there is an asset list, e.g.: monitor1, laptop1, laptop2.
I want update the attribute Status of all objects in the ticket regardless of their type. I have a working solution if the object Status value is not null (earlier somehow was set), but it's not working, if the attribute is empty:
assetList.each{asset ->
def insightObject = iqlFacade.findObjectsByIQLAndSchema(schemaId, "key = " + asset.getObjectKey()).first();
def attributeId = insightObject.objectAttributeBeans.find {
objectTypeAttributeFacade.loadObjectTypeAttributeBean(it.objectTypeAttributeId).name == "Status"
}?.objectTypeAttributeId;
def objectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(attributeId);
def newStatusAttributeBean = asset.createObjectAttributeBean(objectTypeAttributeBean);
def newObjectAttributeBean = objectAttributeBeanFactory.createObjectAttributeBeanForObject(insightObject, objectTypeAttributeBean, "NewStatusName");
def objectAttributeBean = objectFacade.loadObjectAttributeBean(insightObject.getId(), objectTypeAttributeBean.getId());
if (objectAttributeBean != null) {
newObjectAttributeBean.setId(objectAttributeBean.getId());
}
objectAttributeBean = objectFacade.storeObjectAttributeBean(newObjectAttributeBean);
}I can get the ObjectTypeId from the asset and create a new ObjectTypeBean:
def objectTypeId = asset.getObjectTypeId();
def objectTypeBean = objectTypeFacade.loadObjectTypeBean(objectTypeId);
??????
def attributeId = objectTypeBean.getAttributeId.where(name == "Status"); //here I want to get the the current asset attribute id, where the attribute name is Status
??????
But I don't know, how to get the attributeId of the current object type Status attribute by the name of the attribute!