I am attempting to use the SharedVariable of the IPluginExecutionContext between different calls to the same plugin. I have the following scenario:
The user is attempting to create a new Entity Record and the plugin has been triggered on the Pre stage. Based on some logic, I am setting a SharedVariable like so:
var context = (IPluginExecutionContext) serviceProvider.GetService(typeof (IPluginExecutionContext));
context.SharedVariables.Add("MySharedVariable", true);
I then attempt to update other records of the same entity like so:
var qe = new QueryExpression("new_myentity");
qe.Criteria.AddCondition("ecs_myfield", ConditionOperator.Equal,"someValue");
var results = service.RetrieveMultiple(qe);
foreach (var foo in results.Entities)
{
//Do something to foo
service.Update(foo);
}
I also have a plugin registered for Update on the Pre stage, however, I want to check MySharedVariable and do something else based on whether or not it is set.
In the Update, the context does not contain the key for 'MySharedVariable'. I have confirmed this by using the ITracingService.
Is there some restriction on passing shared variables between plugins that are run on different records?
The plugin execution mode for both the Create and Update is set to Synchronous and as already explained, both are registered on the Pre Operation stage