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);
This will be included in the next minor release. If you would like to try a pre-release version and provide any feedback you can download it here:
- VS2022 - https://xrmtoolkit.com/downloads/xrmtoolkit.x64_8_3_0_0.vsix
- VS2017/VS2019 - https://xrmtoolkit.com/downloads/xrmtoolkit_8_3_0_0.vsix
The plugin registration tool has been updated to be able to register on the new messages and the 'BasePlugin' class that is generated has been updated to support the bulk messages.