Notifications
Announcements
No record found.
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
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.
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"]; }
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.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2