Using Azure functions as a scheduler for Dynamics 365

A few months ago I had a requirement where I needed to flag records as expired which were past their expiry date within Dynamics. I have seen/implemented various techniques before that involved using Dynamics itself as the scheduling engine, but that wasn’t always consistent nor performant. I have also been done the path of creating console applications that are then setup to execute on a server on a scheduled basis. These previous solutions always involved a lot of work or were not reliable and hence I wanted to explore a different option this time around.

So for my scenario, I needed a process to run at approximately 23.45pm every day and find records (e.g Drivers Licenses) that had an expiry date on or before the current date and were not flagged as expired. These records would then need to be flagged as expired.

Below is the solution implementation overview:
* Created a new Azure function in Visual Studio that is based on a timer trigger
* Added a reference to the CRM core SDK NUGET assemblies within the function
* Created the Dynamics query for the records meeting the specific conditions and flagged them as expired
* Set the scheduler to run at 23.45pm local time (More details on the format of that syntax can be found here
* Used Azure DevOps to deploy the function into Azure
* That was it!

As I have been drafting this blog post, there have been some great blog posts this week on this topic too by Asha and Salim so check those out for more of the technical bits.

What I wanted to elaborate on was the key advantages I realized with this approach:
1. Speed to market – I was able to get this all up and running in an hour or so. It was surprising simple and familiar to create and deploy this function.
2. Resilient & efficient – Azure functions run on “serverless architecture” and also aren’t constrained by the Dynamics 2 mins execution limitation. The function has been running consistently on a daily basis for the last 2 months. No more restarting workflows or logging onto servers to reset a system job! Azure functions have very robust debugging/troubleshooting capabilities too both when using Visual Studio or the Azure portal.
3. Cost – Azure functions are very cost effective. You do not need to worry about licenses servers. The cost primarily depends on your consumption of resources and in the above implementation, we aren’t “paying” for anything as the usage is well under the quotas provided. More details on pricing can be found here

Overall, Azure functions are now another go-to option to consider when faced with various integration/scheduling requirements. The challenge/balance is knowing when to use Azure functions, Flow or Logic Apps but Ill save that blog post for another day!