0

I have a restricted action script that looks to see if a specific property has changed and stores the new value in the PropertyBag. It's based on this example in the documentation.

using System.Linq;

var targetItem = Context.Target as IEntity ?? await MClient.Entities.GetAsync(Context.TargetId.Value);

if (targetItem == null) {
    MClient.Logger.Error($"Unable to get asset for Context.TargetId: {Context.TargetId} (Context.TargetType: {Context.TargetType})");
    return;
}

if (Context.ChangeTracker == null) 
{
    MClient.Logger.Error("Context.ChangeTracker is null");
    return;
}

var titleOriginal = Context.ChangeTracker.GetOriginalPropertyValue<string>("Title");
var titleCurrent = await targetItem.GetPropertyValueAsync<string>("Title");

if (titleOriginal.Equals(titleCurrent))
{
    MClient.Logger.Info($"The title of asset {targetItem.Id} was not changed: {titleOriginal}");
}
else
{
    MClient.Logger.Info($"The title of asset {targetItem.Id} was changed from \"{titleOriginal}\" to \"{titleCurrent}\"");

    Context.PropertyBag.Add($"{targetItem.Id}_title", titleCurrent);
}

However, when it runs, the Context.ChangeTracker is always null:

log entries

Anyone have any ideas why the ChangeTracker would never be set?

Things I've tried:

  1. Verifying the script is restricted and the trigger is set to run in process
  2. Making a change to multiple properties (including the one I care about) to see if different properties would result in the ChangeTracker being hydrated

Content Hub version: 3.1.3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.