0
Answered

Access to source entity fields for target entities returned by CheckFieldUniqueness

Adrian Corston 1 month ago in UNIFYBroker Service updated 1 month ago 5

When using the CheckFieldUniqueness component to ensure target entity field uniqueness I would like to use source entity field values in order to calculate candidate values for the unique field.  I'm only aware of a way to access target entity field values.

Is there a way to access the source entities for a target entity in this scenario?

Otherwise, please change this ticket to an Idea to have the ability to do so.

Affected Versions:
Fixed by Version:

Answer

Answer
Answered

I see. You could just mapping the required values to to fields on the target entities, but assuming you don't want to do that you should process the $joinedEntities collection into a HashTable keyed on the target entities. For example:

$entityMap = @{};

foreach ($joinedEntity in $joinedEntities)
{
    $entityMap[$joinedEntity.TargetEntity] = $joinedEntity.SourceEntity;
}

You'll then be able to use the target entities returned by CheckFieldUniqueness to lookup the corresponding source entity efficiently.



GOOD, I'M SATISFIED
Satisfaction mark by Adrian Corston 1 month ago
Under review

Hi Adrian

See Entity Components, in particular the Source Entities and Joined Entities sections. Also see PowerShell Task, which has an example of using the joinedEntities collection.

Hi Beau,

The examples on those pages only refer to passing $targetEntities to CheckFieldUniqueness().  From a target entity, is it possible to get to source entity fields of the target entity for which a unique field value is to be calculated?

I want to be able to use source entity fields to generate a unique value in the target entity.

Answer
Answered

I see. You could just mapping the required values to to fields on the target entities, but assuming you don't want to do that you should process the $joinedEntities collection into a HashTable keyed on the target entities. For example:

$entityMap = @{};

foreach ($joinedEntity in $joinedEntities)
{
    $entityMap[$joinedEntity.TargetEntity] = $joinedEntity.SourceEntity;
}

You'll then be able to use the target entities returned by CheckFieldUniqueness to lookup the corresponding source entity efficiently.



Thanks Beau, I'll use the suggested entity map approach.

I confirm this approach works correctly as described by Beau.