C# code in Power Automate: let’s sort a string array?

By | September 16, 2021

In the previous post, I wrote about how we can use C# code in Power Automate connectors now. The example given there (converting a string to uppercase) was not that useful, of course, since we could simply use an expression and a “toUpper” function directly in the expression.

So I thought of a more useful application of this new functionality, and, it seems, sorting string arrays might be one of those.

Mind you, it can be done without c# code. For example we could run an office script:


Which looks like a valid option (it’s coding anyways), but, if we did not want to use office connectors (or, perhaps, for those of us who would prefer C#), it can also be done with C# using “code” functionality in the custom connector:


You will find both swagger definition and script files for this connector in the git repo:


And there are some explanations below

1. SortStringArray operation will have arrays as both input and output parameters


2. In the code, incoming array will be converted into a string array, then sorted, then sent back through the response


That’s quick and simple; although, I have to admit it took me a few hours to figure out all the plumbing (swagger definitions, using JArray above, etc). But, I guess, it’s fine to expect a bit of a learning curve initially.

What definitely helped, though, is creating a small project in the Visual Studio and testing some of the same code there.

Anyways, that’s all for now!

Leave a Reply

Your email address will not be published. Required fields are marked *