{
Entity updConfig = new Entity(new_configuration.EntityLogicalName.ToString());
updConfig.Attributes.Add("new_configurationid", configId);
updConfig.Attributes.Add("new_aivalue", true);
_service.Update(updConfig); // <- triggers the post-update plugin which increments the value and adds it to the shared variable
{
return (int)context.SharedVariables["NEW_AIV"];
}
else
{
IPluginExecutionContext nContext = context;
while (nContext.ParentContext != null)
{
if (nContext.ParentContext.SharedVariables.Contains("NEW_AIV"))
{
return (int)nContext.ParentContext.SharedVariables["NEW_AIV"];
}
nContext = nContext.ParentContext;
}
}
}
Post-update plugin that adds the value to "shared variables":
{
IPluginExecutionContext context = localContext.PluginExecutionContext;
Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null;
if (localContext.TargetEntity.Contains("new_aivalue")) // FIRE PLUGIN
{
new_configuration currentConfig = postImageEntity.ToEntity<new_configuration>();
int value = Convert.ToInt32(currentConfig.new_value);
string strvalue = string.Empty;
ct.SharedVariables.Add("NEW_AIV", (Object)value);
while (ct.ParentContext != null) // Try adding value to all "shared variables" in parent contexts...
{
ct = ct.ParentContext;
ct.SharedVariables.Add("NEW_AIV", (Object)value);
}
strvalue = Convert.ToString(value + 1);
new_configuration updConfig = new new_configuration() { new_configurationId = localContext.TargetEntity.Id, new_value = strvalue };
localContext.OrganizationService.Update(updConfig);
}
}
By doing some "ugly logging" I can verify that the value is added to the shared variables and exists there in the post-update plugin but it does not exists later when the pre-create plugin continues its execution.

Report
All responses (
Answers (