J

Friday, June 9th, 2023 10:00 AM

Adding multiple assets with multiple attributes from excel file

I am creating a workflow to add 2 different kind of attributes while creating an asset. I am getting all this asset and attribute values from an excel sheet. But I am unable to get the asset Id of the new asset for adding the attribute. Please find the below code which I have tried,

for(assetMap in assetMapList){
addAssetList.add(AddAssetRequest.builder()
.name(assetMap.assetName)
.domainId(string2Uuid(assetMap.domainId))
.typeId(string2Uuid(assetMap.assetTypeId))
.build()
)
addAttributeList.add(AddAttributeRequest.builder()
.assetId(string2Uuid(assetMap.assetName.getId()))
.typeId(string2Uuid(assetMap.attributeType1))
.value(assetMap.attributeValue1)
.build()
)
addAttributeList.add(AddAttributeRequest.builder()
.assetId(string2Uuid(assetMap.assetName))
.typeId(string2Uuid(assetMap.attributeType2))
.value(assetMap.attributeValue2)
.build()
)
////

		//def assets_new = assetApi.addAssets(addAssetList)
		//loggerApi.info("assets_new: ${assets_new}")
		////
	}

1.2K Messages

2 years ago

Huh, interestingly I never noticed that “AddAssets” methods, I only used the AddAsset method.
Well, it returns List<Asset>, so you can use it to enrich your list.

I don’t really understand why you write assetMap.assetName.getId(), it’s not very clear what is in your assetMap. Are you copying assets from one domain to another

Anyways:

  1. You cannot know the ID until you execute assetApi.addAssets(addAssetList), so you should split your iteration in two (one for assets, one for attributes)
  2. Why not use an importApi instead? This way you can process everything at once.
  3. I guess the only way to reconciliate assets_new and assetMapList is based on the name of the asset which must be unique. So you could index a new map based on assets_new, using the name as the key.

9 Messages

It works! Thanks…dg

Loading...