2

We have a scenario where we need to calculate multiple fee components & share between Pre & Post stages of a Plugin. So we created the object like this.

class FeeCalculation
    {
        public string TotalFee { get; set; }
        public string FilingFee { get; set; }
        public string LegalFee { get; set; }
        public string RecordFee { get; set; }
    }

So far we have used single fee component & shared variable worked nicely. When tried to assign the whole object - the result is not fruitful.

context.SharedVariables.Add("fees", fcObject);

Is there a way to achieve this expected result?

2 Answers2

5

The plugin infrastructure must be able to serialize/deserialize the objects that are in your SharedVariables collection. It has no knowledge of custom types like the FeeCalculation class and therefore cannot serialize it.

Use primitive types, common .NET types (e.g. a List of decimals should work) or CRM types (Entity, Money etc.). It's good to note that the SharedVariables collection is a key value pair collection. So, why not just add items to it with keys like "TotalFee", "FilingFee" etc?

Henk van Boeijen
  • 7,357
  • 6
  • 32
  • 42
0

I was trying to share an IEnumerable<Guid>, but collections like List did not work.

Of course you can always serialize to string, but your plugin code really shouldn't have to deal with serialization of common types.

After some trial and error, I ended up using arrays, i.e. Guid[].

avolkmann
  • 2,962
  • 2
  • 19
  • 27