Hi
I am trying to build a workflow that takes the information from an attribute of an asset and the name of the same asset to create a unique full name. This is what I have come up with so far with the help of chatgpt 😅:
import com.collibra.dgc.core.api.component.instance.AssetApi;
import com.collibra.dgc.core.api.dto.instance.asset.FindAssetsRequest;
import com.collibra.dgc.core.api.dto.instance.asset.SetAssetAttributesRequest;
import com.collibra.dgc.core.api.dto.instance.asset.ChangeAssetRequest;
import com.collibra.dgc.core.api.component.logger.LoggerApi;
import com.collibra.dgc.workflow.api.exception.WorkflowException;
import com.collibra.dgc.core.api.dto.instance.attribute.FindAttributesRequest;
// Fetch current asset
currentAsset = assetApi.getAsset(item.getId())
// Search for the Model ID attribute
def IDattributeValue = attributeApi.findAttributes(FindAttributesRequest.builder()
.assetId(item.id)
.typeIds([string2Uuid(AttributeResourceMID)])
.build())
// Check if the Model ID attribute was found
if (IDattributeValue == null || IDattributeValue.isEmpty()){
loggerApi.error("Model ID attribute not found for asset ID: " + item.id());
return;
}
def modelID = IDattributeValue.get(0).getValue()
// Search for the asset name using FindAssetsRequest
def findAssetsResponse = assetApi.findAssets(FindAssetsRequest.builder()
.name(currentAsset.getName()) // Use the name of the current asset to find it
.build())
// Check if any assets were found
if (findAssetsResponse == null || findAssetsResponse.getResults().isEmpty()){
loggerApi.error("No asset found with the name:" + currentAsset.getName());
return
}
// Get the first result's name (if you want to use the same asset name)
def modelName = findAssetsResponse.getResults().get(0).getName();
// Create the new full name
def newFullName = modelName + "_" + modelID;
// Create a new Full Name
ChangeAssetRequest changeAssetRequest = ChangeAssetRequest.builder()
.assetId(currentAsset.getId())
.displayName(newFullName) // Set the new display name
.build()
// Update the asset display name
assetApi.changeAsset(changeAssetRequest);
loggerApi.info("Updated asset display name to: " + newFullName)
} else {
loggerApi.error("No asset found with the name: " + currentAsset.getName())
}
} else {
loggerApi.error("Model ID attribute not found for asset ID: " + item.id)
}
Unfortunately this doesn't work and I do not know why. Is it possible at all to change the Full Name with a workflow?