I am having a dictionary object with 5 values in it. Now I want to add this to the plugin context shared variable. Is it possible?
*This post is locked for comments
I am having a dictionary object with 5 values in it. Now I want to add this to the plugin context shared variable. Is it possible?
*This post is locked for comments
Would add to Joseph's response that you have to keep serialization in mind:
msdn.microsoft.com/.../gg328579.aspx
"It is important that any type of data added to the shared variables collection be serializable otherwise the server will not know how to serialize the data and plug-in execution will fail."
Dictionary itself should not a problem as long as everything there is serializable.
You question does not make it clear of the code context where you have the dictionary object but I think it is possible using one of the following approaches
This script I have copied below demonstrates sharing a dictionary object between prevalidation, preoperation and postoperation stages for the create, update or delete messages. Note that the preoperation and postoperation stages actually have to access the parent context to get a shared variable from the prevalidation message
If the context where you have the dictionary is outside of a plugin, and you want to pass the dictionary into code in the plugin message, you would probably have to use a custom field(s). You could set a text field to the serialised dictionary, then get and deserialise it inside the plugin
if(IsStage(PluginStage.PreValidationEvent)) { var dictionary = new Dictionary<string, string> { { "Key1", "Value1" }, { "Key2", "Value2" }, { "Key3", "Value3" }, }; IPluginExecutionContext.SharedVariables.Add("DICTIONARY1", dictionary); } if (IsStage(PluginStage.PreOperationEvent)) { var getDictionary = (Dictionary<string, string>)IPluginExecutionContext.ParentContext.SharedVariables["DICTIONARY1"]; var dictionary2 = new Dictionary<string, string> { { "Key1", "Value1" }, { "Key2", "Value2" }, { "Key3", "Value3" }, }; IPluginExecutionContext.SharedVariables.Add("DICTIONARY2", dictionary2); } if (IsStage(PluginStage.PostEvent)) { var getDictionary1 = (Dictionary<string, string>)IPluginExecutionContext.ParentContext.SharedVariables["DICTIONARY1"]; var getDictionary2 = (Dictionary<string, string>)IPluginExecutionContext.SharedVariables["DICTIONARY2"]; }
Hi Ancy. I don't think it is possible. You may want to create a custom entity with just name and value fields to store your dictionary data, and retrieve them from other plugins.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156