Full disclaimer… this post was triggered by what a fellow MVP, Olena Grischenko, wrote earlier today: https://msolenacrm.blog/2020/06/18/power-automate-for-cds-what-was-it-before-we-run-the-update-or-byebye-no-code/
I am all for plugins, I actually write them every day But, then, should not there be some way to work with pre/post images in PowerAutomate? Without code?
And there is one, although “no code” solutions are not, always, the easiest:
Basically, we can set up CDS to send pre/post/target data to a queue in Azure Service Bus. It’s not a complicated process, you just need to follow the steps described here:
Just make sure to use json message format when setting up the integration:
Once that is done, you can start adding SDK steps. And, for those SDK steps, you can start adding pre/post images:
Let’s say that’s been done.
The next step would be creating a flow. PowerAutomate has a connector for Azure Service Bus:
So, set up the trigger:
The remaining part is all about parsing that json from the message queue. Unfortunately, there is no “native” regex capability in Flows, though there are a few third-party connectors there. I did not try those, pretty sure they would work, but this is where “no code” is not the same as “no fees”
Instead, I just opted to tweak the regex custom connector which I blogged about some time ago:
Here is the code I used for the regex action this time:
Now, once there is a regex connector, I just need to add a couple of action to extract “name” field from the pre image:
And, also, to extract it from the post image:
This is where you may have to look at the json and figure out how to write that regex expression (might need to test it in the regex tester).
Once that is done, I can access both pre-image and post-image values of the “name” attribute. In my case, I simply sent an email to myself:
And, once the email came in, both value are there:
What are the caveats?
- We need to create azure service bus queue
- We can’t rely on the capabilities of the CDS connector. Although, plugin registration tool is a powerful tool, so this is really a problem for the next step
- Since we do need to figure out how to parse that json
But, in either case, except for the regex connector, this is a no-code solution to the problem. Might actually be possible to just use a bunch of “substring” and “indexof” function calls to do the same, but it’s probably easier to just set up that custom regex connector (or to subscribe to one of those which are already available in Power Automate)
? The absolute coding magic.
Alex, a serious question: what do you code in your everyday plugins? What kind of problems do you still solve with a code and why it is a code, not Power Automate. Too long? Write another blog post. I am starting a massive discussion as a part of my new user group activities. I’m very interested in the topic.
Good question – it may require a post to explain this better, but, usually, there are 2 reasons: the ability to execute synchronously would be one, though, maybe, not the most important (although, I would not say it’s not important, since this is all about user experience), and the other reason is that between two solutions to any relatively complex problem (as in, balance calculations, for example), code solution, if it’s straightforward, will usually be more structured and easier to maintain. Of course there is another side to it, which is non-cds connections. With the plugins, Microsoft has already taken care of that part by providing an excellent SDK, but, when there is an external connection and there is no SDK/API, but, instead, there is a Flow connector… I’d probably use a Flow (maybe still with a custom action on the CDS side:) )
This is good but I didn’t what problem are we trying to solve using htis?
Post/Pre images is all about the ability (in CDS) to see what the value was before operation and comparing it to what it became after the operation (actually, there can be 3 values: “pre”, “post”, and “target”). For example, if you assign a sales order to another sales rep, you might want to recalculate some kind of total for the original rep (old value) and for the new rep (new value)
Alright- got it!
Thanks for clarifying Alex