Hi everyone,
Two days ago I posted a question asking if I could run JavaScript from a workflow and the answer was (and remains) "no, you cannot do that". I had put a lot of work into writing the code before I found out it couldn't be used at all. I was pretty bummed about it but didn't want to give up.
(This was an internal project and the requirements weren't communicated well. I also didn't ask enough questions.)
I ended up pulling together two services in Azure and, with this post, I want to share with the community that I was able to change that "no" to a "yes". And you don't need to know C# to do it. In my case I only needed to use PowerShell.
What did I do? I made an Azure Logic App and an Azure Function. The Logic App checks for new records on an entity, gathers some information abut them, executes the Azure Function, and then, finally, writes the result of the function back to CRM.
The Azure Function itself uses PowerShell (and Invoke-RestMethod) to make a POST request to UPS' API to get Time in Transit data for packages. UPS doesn't have any documented JavaScript code so I couldn't get it to work with XMLHttpRequest from CRM. I had no problem doing it with PowerShell on my machine so I made an Azure Function that I could then call with XMLHttpRequest from CRM.
Before I got started on creating a Logic App, I already had my Function in place and working. Starting from scratch I'd say the Function was the most difficult part. Their PowerShell support is still in Preview so it's not really well documented. All the pieces took some experimentation and it was tedious to test the whole thing.
My solution is a bit complex for what I'm doing but once you wrap your head around all the pieces it's not too bad. I found it to be a rewarding experience and the GUI designer for Logic Apps is quite good.
I left this post light on the details because it's not a blog (maybe I should start one...?).
Here's a screenshot of the Logic App. Each of those steps can be opened to reveal a form used to configure the step.
I'm happy to answer any questions you might have.
*This post is locked for comments