Improvements for the new CreateMultiple and UpdateMultiple messages
The new messages are available for plugins. More info here: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/write-plugin-multiple-operation?tabs=single
We can already register plugins for them using XrmToolkit but some things are missing.
we cannot add filtering attributes for the UpdateMultiple, which is possible using the PluginRegistrationTool
Those messages have a new InpotParameter "Targets" that is an EntityCollection. It would be great to have it available in the LocalPluginContext class.
Proposed implementation (tested):
// as EntityCollection
internal virtual EntityCollection TargetEntityCollection => PluginExecutionContext.InputParameters.TryGetValue("Targets", out EntityCollection value) ? value : null;
or
//as List<Entity>
internal virtual List<Entity> TargetEntities => PluginExecutionContext.InputParameters.TryGetValue("Targets", out EntityCollection value) ? value?.Entities?.ToList() : null;Example usage in plugin:
var targets = localContext.TargetEntities;
targets.ForEach(entity => localContext.TracingService.Trace($"Processing entity with id: {entity.Id}"));var entities = localContext.TargetEntityCollection?.Entities?.ToList();
entities.ForEach(entity => localContext.TracingService.Trace($"Processing entity with id: {entity.Id}"));Similar support could be used for the PreEntityImagesCollection and PostEntityImagesCollection
Proposed implementation (not tested):
internal virtual List<T> PreImages => PluginExecutionContext.PreEntityImages?.Select(x => GetEntityAsType(x.Value)).ToList();
internal virtual List<T> PostImages => PluginExecutionContext.PostEntityImages?.Select(x => GetEntityAsType(x.Value)).ToList();What could also be useful is some method to find a pre/post image for a given target
Proposed implementation (not tested):
internal virtual T FindPreImageForEntity(Entity target) => PreImages?.FirstOrDefault(x => x.Id == target.Id);
internal virtual T FindPostImageForEntity(Entity target) => PostImages?.FirstOrDefault(x => x.Id == target.Id);