This sample provides several Plug-in types that demonstrate how to write plug-ins for the CreateMultiple
and UpdateMultiple
messages.
- Access to Dataverse with system administrator or system customizer privileges.
- Understanding of how to write and register plug-ins.
-
Clone or download the PowerApps-Samples repository.
-
Run the Create and Update Multiple Sample with the setting
DeleteTable
set tofalse
.Note: This will create the tables needed for the plug-ins in this sample.
-
Open the PowerApps-Samples/dataverse/orgsvc/xMultiplePluginSamples/xMultiplePluginSamples.sln
-
Build the solution
-
Use the Plug-in Registration tool (PRT) to upload the
\xMultiplePluginSamples\bin\Debug\net462\xMultiplePluginSamples.dll
to the environment you ran the sample in step 2. -
Use the PRT to register the plug-ins listed in the Plug-in Type list below.
Important: Make sure that the following two plug-ins are not enabled at the same time:
FollowupPluginSingle
andFollowupPluginMultiple
.UpdateSingle
andUpdateMultiple
.
-
Run any of the projects in the Create and Update Multiple Sample, but set a break point before the records are deleted.
-
In Power Apps, navigate to Dataverse > Tables and locate the Example table.
-
Click the Edit button to view the records created.
-
Add the Description column to the view.
-
Repeat and observe the differences when different projects in the Create and Update Multiple Sample are run. The
Description
field should include the name of the project. -
Turn on tracing and view the traces written to the
PluginTraceLog
Table. The XrmToolBox Plugin Trace Viewer is recommended for this. More information: Tracing and logging.
This sample provides an experience where you can observe and interact with plug-ins that are written for the CreateMultiple
and UpdateMultiple
messages.
This sample depends on the Create and Update Multiple Sample so that the merged message processing pipeline behaviors can be verified.
The Create and Update Multiple Sample contains 4 separate projects that do the same thing in different ways.
-
Create a new custom table named
sample_example
if it doesn't already exist. -
Prepare a configurable number of
sample_example
entity instances for the custom table representing records to create. -
Create the
sample_example
records. Each project uses a different method.Note: Each project will pass a
tag
parameter with the name of the project so that it is available as a shared variable to the plug-in. This value will be used by theCreateMultiplePreOp.cs
plug-in in this sample. -
Update the set of entity instances that were created by appending text to the
sample_name
attribute. -
Update the
sample_example
records using the same method they were created. -
Use a BulkDeleteRequest to delete the
sample_example
records created and report on the success of this request. -
Delete the custom
sample_example
table created in the first step, unless configured not to.
Important To run this sample you must first run the Create and Update Multiple Sample with the setting
DeleteTable
set tofalse
. This will create the table this sample depends on.
This sample contains the following plug-in types designed to interact with the operations performed by the Create and Update Multiple Sample, or to help visualize the changes to the executioncontext with each message.
Plug-in Type | Message | Stage | Description |
---|---|---|---|
ContextWriter.cs |
Any | Any | Use this plug-in to write details of the IPluginExecutionContext4 to the trace log so that you can see the values being passed. Add entity images in the step registration to view the content. |
CreateMultiplePreOp.cs |
CreateMultiple | PreOperation (20) | Sets the sample_description attribute value to $"'tag' value for Create = '{tagValue}'." where tagValue is the value set using the optional tag parameter. |
FollowupPluginMultiple.cs |
CreateMultiple | PostOperation (40) | This is the replacement for FollowupPluginSingle.cs .Creates a task record associated with the sample_example record created. |
FollowupPluginSingle.cs |
Create | PostOperation (40) | Creates a task record associated with the sample_example record created. |
UpdateMultiple.cs |
UpdateMultiple | PreOperation (20) | This is the replacement for UpdateSingle.cs .Uses an Entity image named example_preimages from the matching item in the PreEntityImagesCollection to compare the original sample_name value with the value in the update operation. When the values are different, append a message to the sample_description attribute value: $"\\r\\n - 'sample_name' changed from '{oldName}' to '{newName}'." , where oldName is the original value and newName is the new value. |
UpdateSingle.cs |
Update | PreOperation (20) | Uses a PreEntityImage named example_preimage to compare the original sample_name value with the value in the update operation. When the values are different, append a message to the sample_description attribute value: $"\\r\\n - 'sample_name' changed from '{oldName}' to '{newName}'." , where oldName is the original value and newName is the new value. |
This sample includes plug-ins written for the CreateMultiple
and UpdateMultiple
messages using the guidance provided in Write plug-ins for CreateMultiple and UpdateMultiple (Preview).
Two of the plug-ins, FollowupPluginSingle.cs
and UpdateSingle.cs
, represent the 'before' plug-in written for the Create
and Update
messages. The FollowupPluginMultiple.cs
and UpdateMultiple.cs
plug-ins represent the 'after' plug-ins written for CreateMultiple
and UpdateMultiple
messages.
By contrasting these plug-ins, you can observe how logic applied for the single operation can be modified to work with the operation that includes multiple entities.
The ContextWriter.cs
plug-in captures data from the IPluginExecutionContext4 Interface and writes it to the PluginTraceLog table so that you can see the data passed to the plug-in.
- How to write plug-ins for the
CreateMultiple
andUpdateMultiple
messages - How to modify existing plug-ins using
Create
andUpdate
to useCreateMultiple
andUpdateMultiple
messages. - How to write information about the plug-in execution context to the plug-in trace log.