List of Data Owners and Data Stewards workflow script
Hi,
I'm new to Collibra and I just started working with processes. I wanted to create a workflow that, based on the selected role (Data Owner or Data Steward) from a community chosen by the user, sends an email with the names of the people who have that role. I can't get the code to work properly, and as far as I know, it's because it won't let me deploy the application. I don't know if anyone could help me by giving me a tip or pointing out where the error might be
Thank you so much
Best regards, Lara
import com.collibra.dgc.core.api.dto.instance.responsibility.FindResponsibilitiesRequest
import com.collibra.dgc.core.api.dto.user.FindUsersRequest
import com.collibra.dgc.workflow.api.exception.WorkflowException
import java.util.UUID
// Obtener el ID de la comunidad seleccionada
UUID communityId = execution.getVariable("community")
loggerApi.info("Community ID seleccionado: " + communityId)
if (communityId == null) {
throw new WorkflowException("No se ha seleccionado ninguna comunidad.")
}
List<String> roleNameList = ["Data Owner"]
List<UUID> roleIds = []
// Obtener el ID del rol "Data Owner"
try {
roleNameList.each { roleName ->
UUID roleId = users.getRoleId(roleName)
if (roleId != null) {
roleIds.add(roleId)
loggerApi.info("Role ID encontrado para " + roleName + ": " + roleId)
} else {
throw new WorkflowException("No se encontró el rol: " + roleName)
}
}
} catch (Exception e) {
loggerApi.error("Error al obtener el ID del rol: " + e.getMessage())
throw new WorkflowException("Error al obtener el ID del rol: " + e.getMessage())
}
if (roleIds.isEmpty()) {
throw new WorkflowException("No se encontraron roles válidos para 'Data Owner'.")
}
String ownerName = ""
try {
def responsibilities = responsibilityApi.findResponsibilities(
FindResponsibilitiesRequest.builder()
.resourceIds([communityId])
.roleIds(roleIds)
.includeInherited(true)
.build()
).getResults()
loggerApi.info("Número de responsabilidades encontradas: " + responsibilities.size())
if (!responsibilities.isEmpty()) {
def responsibility = responsibilities.get(0)
def owner = responsibility.getOwner()
if (owner != null && owner.getResourceType().toString().equals("User")) {
UUID userId = owner.getId()
loggerApi.info("Responsabilidad encontrada con User ID: " + userId)
def user = userApi.getUser(userId)
if (user != null) {
ownerName = "${user.getFirstName()} ${user.getLastName()}"
loggerApi.info("Data Owner encontrado: " + ownerName)
} else {
throw new WorkflowException("No se pudo obtener la información del usuario con ID: " + userId)
}
} else {
throw new WorkflowException("El dueño de datos no es un usuario, puede ser un grupo.")
}
} else {
throw new WorkflowException("No hay Data Owner asignado a la comunidad seleccionada.")
}
} catch (Exception e) {
loggerApi.error("Error al buscar responsabilidades: " + e.getMessage())
throw new WorkflowException("Error al buscar responsabilidades: " + e.getMessage())
}
// Save name Data Owner
execution.setVariable("dataOwnerName", ownerName)
loggerApi.info("Data Owner Name: " + ownerName)
Sean Pyle
·1 year ago · EditedHey Lara,
I recreated your script task in my Workflow Designer environment and I was able to successfully deploy it, so I would say your script seems to be fine.
Where are you getting the community variable that you imported from execution? I think that might be causing your issues. If you're storing it as a form property, I recommend checking its configuration first. Form properties like communities need to use the "custom type."