This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Community Hub.
I recently was asked the question; how do I pass in a complex object to custom code? In this post, we are going to explore this topic.
When you create a new local function, we will provision sample code that you can use to get started. Within this sample code, we include primitive types as inputs to the function and then return a complex Weather object. When the function returns context back to the workflow, we have access to all the properties from that complex object in our workflow as dynamic content.
So the question, is what if I want to pass a complex object into my function? Do I have to perform any type casting? The answer is no.
I have updated the sample to include a complex object called WeatherRequest. I can now access any properties in this complex object by referencing objectname.property.
WeatherRequest class
I can now compile this code and the assembly and dependencies will be bin placed into the workflow project. I will now update my workflow to pass in a JSON object that matches the format of my complex object. Using the json2csharp website can help with converting JSON objects into C# code.
In my workflow, I will add a Compose action that I can use to create a JSON object.
I can then pass my Compose action into the WeatherRequest input parameter.
Our code will now execute and return a response back to our workflow.
Video Content
If you would like to see a live demo of this in action, please refer to the following video.