Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

[Followup] Can I run a JS function from a workflow?

(1) ShareShare
ReportReport
Posted on by 221

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.

09_5F00_20_5F00_00_2D00_Logic-Apps-Designer-_2D00_-Microsoft-Azure.png

I'm happy to answer any questions you might have.

*This post is locked for comments

  • f23fzf34ffavcz2t56 Profile Picture
    f23fzf34ffavcz2t56 221 on at
    RE: [Followup] Can I run a JS function from a workflow?

    Thanks! But I might not be able to exit my office if my head gets any bigger. haha

    Regarding Flow, I did a bit of testing just now and it looks like you can't use Azure Functions as a step. So that rules that out.

  • RE: [Followup] Can I run a JS function from a workflow?

    You are brilliant!

    Thinking outside of the box would be a trend everyone should embrace. Other than logic app, Microsoft flow is also another alternative.

    Not sure but do you research how many calls can be triggered per day? There is some limitations for free tier, especially on the time trigger.

    And thanks to you, developers will have headache finding something that's not within the CRM box, especially when comes to deployment etc.

    Anyway, KUDOS!

  • f23fzf34ffavcz2t56 Profile Picture
    f23fzf34ffavcz2t56 221 on at
    RE: [Followup] Can I run a JS function from a workflow?

    Hi Alex,

    You bring up some very valid points but, for me, this solution is valuable for a few reasons.

    I'm a lone IT sysadmin at a small company. I know PowerShell and a bit of JavaScript (because I've done some web work in the past). Not knowing C# makes creating a plugin myself a non-starter. I've worked with contractors in the past to build custom plugins but I tend to shy away from that as a solution because they are impossible (for me) to modify. A custom solution that I can make gives me a lot more flexibility in the future.

    In my case, I've been itching to find opportunities where I can utilize tools to automate tasks and integrate disparate systems. This was a perfect opportunity for that once I found out I couldn't go my expected route.

    Knowing how to use Azure Logic Apps and Functions opens up a plethora of possibilities for me in IT. Particularly the fact that it was so easy to work with.

    Ultimately, if I were a C# developer, or I had a developer on staff, I probably wouldn't have given this Azure solution a first thought. I would have gone the usual route for the reasons you stated.

    I hope this helps explain where I'm coming from.

    Thanks.

  • ashlega Profile Picture
    ashlega 34,477 on at
    RE: [Followup] Can I run a JS function from a workflow?

    Hey,

     interesting stuff, though I am not sure it's reasonable to do it that way just for the sake of reusing a function. It would not take long to create a CRM plugin, yet it would be solution-aware (meaning that you could add it to the solution and  use it in different environments: dev, test, uat, prod, etc). That said, it's still a nice example of using Azure Logic App with CRM.. so yes, you might want to start a blog:)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,430 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans