We are using a lot of Entities that have child types as keys, like status fields and such, and when a verifier trigger is set to fire on the change event for these types, it doesn't. In the example below, the Status can be several different values (and exists as a related entity to the parent entity) and two of them, disputed or no response, require a comment to be added to the record. The trigger on the comment field fires on set reliably, but the status change trigger only fires during the entity save, not during the property set.
Here's the code: (the DealConfStatus is a type, the ConfComment is a string).
[
VerifierProvider]
public static IEnumerable<Verifier> GetVerifiers(object verifierProviderContext)
{
List<Verifier> verifiers = new List<Verifier>();
verifiers.Add(DisputeOrNoResponseStatusVerifier());
verifiers.Add(DisputeOrNoResponseCommentVerifier());
return verifiers;
}
private static Verifier DisputeOrNoResponseStatusVerifier()
{
string description = "When a confirm is marked Disputed or No Response, the Comment must be updated";
DelegateVerifier<DealConfirmation> verifier = new DelegateVerifier<DealConfirmation>(description, DisputeCommentVerifierCondition);
verifier.AddTrigger(
DealConfirmation.EntityPropertyNames.DealConfStatus);
verifier.ExecutionModes =
VerifierExecutionModes.All;
return verifier;
}
private static Verifier DisputeOrNoResponseCommentVerifier()
{
string description = "When a confirm is marked Disputed or No Response, the Comment must be updated";
DelegateVerifier<DealConfirmation> verifier = new DelegateVerifier<DealConfirmation>(description, DisputeCommentVerifierCondition);
verifier.AddTrigger(
DealConfirmation.EntityPropertyNames.ConfComment);
verifier.ExecutionModes =
VerifierExecutionModes.InstanceAndOnPostsetTriggers;
return verifier;
}
private static VerifierResult DisputeCommentVerifierCondition(DealConfirmation dealConf, TriggerContext triggerContext, VerifierContext verifierContext)
{
if (dealConf.DealConfStatus.Key == DealConfStatusEnum.Disputed || dealConf.DealConfStatus.Key == DealConfStatusEnum.NoResponse)
{
return new VerifierResult(DealConfirmation.ConfCommentEntityProperty.GetValue(dealConf, EntityVersion.Original) != DealConfirmation.ConfCommentEntityProperty.GetValue(dealConf, EntityVersion.Current) && dealConf.ConfComment != null && dealConf.ConfComment != "");
}
else
{
return new VerifierResult(true);
}
}