Workflow that creates Full Name
Summary: The author is attempting to build a workflow for creating a unique full name by combining an asset's attribute and its name. They shared their current script, which isn't functioning as expected, and asked if it's possible to change the "Full Name" using a workflow. Another user responded by sharing a previous workflow example they had used, explaining when it would trigger, and providing potential insights. The author later solved the issue themselves and provided the corrected workflow script. The discussion concludes with hopes for future workflows being created through Generative AI from simple English instructions.
.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 😅:
Unfortunately, this doesn't work and I do not know why. Is it possible at all to change the Full Name with a workflow?
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
def 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 ChangeAssetRequest to update the display 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)
Grant Rollerson
·1 year ago · Edited@BUAmina hopefully the day comes in the very near future where we can build workflows via Gen AI based on plain English requirements ;-)
Grant Rollerson
·1 year ago · EditedAt one point, we had a WF for this, but it's no longer needed. Including it below; it may help. I should add I didn't do it, and it might not be right,t but it might give you some ideas...
Also be aware:
When WF uses Start Event "Asset Attribute Changed", it will only work if you manually change the value of the attribute on the Asset Page, and the workflow will be triggered, not for Import via UI.
When WF uses Start Event "Asset Attribute Removed OR "Asset Attribute Added" - this only works when importing via UI and you have Option "8.a Enable workflows during import" enabled in the console
// Execute this at Asset Level // Allow multi select import com.collibra.dgc.core.api.dto.instance.asset.AddAssetRequest import com.collibra.dgc.core.api.dto.instance.asset.ChangeAssetRequest import com.collibra.dgc.core.api.dto.instance.asset.SetAssetAttributesRequest import com.collibra.dgc.core.api.model.instance.Asset import com.collibra.dgc.core.model.relation.Relation import com.collibra.dgc.core.api.dto.instance.asset.FindAssetsRequest import com.collibra.dgc.core.api.dto.MatchMode import com.collibra.dgc.core.api.dto.instance.relation.FindRelationsRequest import com.collibra.dgc.workflow.api.exception.WorkflowException import com.collibra.dgc.core.api.dto.instance.attribute.AddAttributeRequest import com.collibra.dgc.core.api.dto.instance.attribute.ChangeAttributeRequest import com.collibra.dgc.core.api.dto.instance.attribute.FindAttributesRequest import com.collibra.dgc.core.api.dto.instance.relation.AddRelationRequest import com.collibra.dgc.core.api.component.instance.DomainApi import com.collibra.dgc.core.api.dto.instance.domain.FindDomainsRequest // Fetch basic asset details def itemId = item.getId() def itemName = assetApi.getAsset(itemId).getDisplayName() def itemFName = assetApi.getAsset(itemId).getName() loggerApi.info("Item details >> " + itemId + " * " + itemName + " * * " + itemFName) // Check if attribute exists if (!attributeApi.findAttributes( FindAttributesRequest.builder() .assetId(itemId) .typeIds([string2Uuid(fNameAttrTypeId)]) .build() ).getResults().isEmpty()) { // Attribute exists — update it def FNameAttributeId = attributeApi.findAttributes( FindAttributesRequest.builder() .assetId(itemId) .typeIds([string2Uuid(fNameAttrTypeId)]) .build() ).getResults().get(0).getId() attributeApi.changeAttribute( ChangeAttributeRequest.builder() .id(FNameAttributeId) .value(itemFName) .build() ) } else { // Attribute doesn't exist — create it attributeApi.addAttribute( AddAttributeRequest.builder() .assetId(itemId) .typeId(string2Uuid(fNameAttrTypeId)) .value(itemFName) .build() ) } loggerApi.info("Attribute updated")BUAmina
OP1 year ago · Edited@grantrollerson1 - Wow thank you so much for your example. I was able to solve my issue shortly after posing the question. This is how I solved it:
// Import necessary classes from Collibra API import com.collibra.dgc.core.api.component.instance.AssetApi import com.collibra.dgc.core.api.component.instance.AttributeApi import com.collibra.dgc.core.api.dto.instance.asset.FindAssetsRequest import com.collibra.dgc.core.api.dto.instance.asset.ChangeAssetRequest import com.collibra.dgc.core.api.dto.instance.attribute.FindAttributesRequest import com.collibra.dgc.core.api.component.logger.LoggerApi import com.collibra.dgc.workflow.api.exception.WorkflowException // Fetch the current asset with item.id def currentAsset = assetApi.getAsset(item.id) // Search for the Model ID attribute def IDattributeValue = attributeApi.findAttributes( FindAttributesRequest.builder() .assetId(currentAsset.id) // ID of current asset .typeIds([string2Uuid(AttributeResourceMID)]) // AttributeResourceMID is defined in start node .build() ) // Check if attribute is found if (IDattributeValue.results.isEmpty()) { throw new WorkflowException("No attributes found for the given asset ID.") } // Save value of found attribute def modelID = IDattributeValue.results.get(0).value // Search for the asset name using FindAssetsRequest def findAssetsResponse = assetApi.findAssets( FindAssetsRequest.builder() .name(currentAsset.name) .build() ) // Check if asset with name is found if (findAssetsResponse.results.isEmpty()) { throw new WorkflowException("No assets found with the name: ${currentAsset.name}") } // Save name of found asset def modelName = findAssetsResponse.results.get(0).name // Create the new full name def newFullName = "${modelName}_${modelID}" // Combine Name and ID with an underscore // Create a ChangeAssetRequest to update the asset name def changeAssetRequest = ChangeAssetRequest.builder() .id(currentAsset.id) .name(newFullName) .build() // Update the asset display name assetApi.changeAsset(changeAssetRequest)