Creating Dynamic Variable Types

Hey everyone,

I’m using the Robotic Enterprise Framework to automate processes and some of the older members of the team prefer using the Excel Config file whereas many of the newer members prefer a JSON formatted config that is able to separate information based on runtime environment much easier.

In the “InitAllSettings.xaml” file is has the out_Config that it creates listed as a System.Collections.Generic.Dictionary<System.String, System.Object>.

Is it possible to have it dynamically map the variable type as System.Collections.Generic.Dictionary<System.String, System.Object> if in_ConfigFile.Contains(".xl") OR Newtonsoft.Json.LinqJObject if in_ConfigFile.Contains(".json")?

Thanks in advance for any advice!

Hi @mike.vansickle

I’m not 100% sure which one is the best out of excel or json. However, I would give you a way to use both as you need.

So for your question on how to make the variables dynamic I can propose the below method.

You can have two variables. One Json and one object. Then check the files in the directory using
Directory. Get files

Using the file extension you can check what type of file you have in the specified folder.
Then using a if condition, based on the file extension, assign the values to the relevant variable object or json type.

Once that is done assign the data to the I config directory type and return it to the main workflow as usual. This way you only need to change the workflow it is being read. The rest of the framework will remain the same independent from the fole type you are using for configuration.

Hope it helps to resolve your concern…

Let me know bow it goes…

3 Likes

Hi @mike.vansickle I agree to @Lahiru.Fernando and he gave a good feedback.

Once that is done assign the data to the I config directory type and return it to the main workflow as usual.

For this task following statement is helpfully:
var values = JsonConvert.DeserializeObject(Of Dictionary(Of String, Object))(jsonStringVariable);

This requires e.g. the WebActivitiesPackage and a JSON String with the serialized Dictionary.

In my Projects often I have the ProcessConfig in Excel and the stage/Environment Config in JSON file.
After readIn the JSON, and deserializing in a dictionary I merge this Dictionary with the first one:
dictVar1.Union(dictVar2).ToDictionary(Function( p ) p.Key, Function( p ) p.Value)

2 Likes