RE: How Can I Trigger Workflow Every day (With MS Flow or other solution)
Hey Onur,
You may be able to get by with a calculated field for your Date Difference and use the DATEDIFF function to find the difference between the date fields. This is how we have build any formulas to calculate the difference between two dates, however, the caveat is that being a calculated field a user would have to open up the record in order to have up to date data (which may not be sufficient in your case).
If you wanted to run something daily to calculate the difference, you would have to use either a Custom Workflow (Development), Azure Function (Development), or Power Automate/Flow (Configuration).
Depending on your skill set that may swing your decision, but here is some information for each of them:
- Custom Workflow
- The only way in the CRM system to run a scheduled job (without any external tools) is using a combination of a placeholder table and Bulk Delete Jobs. Bulk Delete Jobs are the only way for us to schedule processes on a specific date, time, and recurrence. You would create a table (say Scheduled Job) and create a single record in this table. You would then have to write a custom workflow to calculate the date difference, which you would then call within a regular workflow. The trigger for this workflow would be on DELETE of the Scheduled Job record. You would then add a line in the workflow to create a new Scheduled Job record so the process can run again. Once the workflows were created, you would then create a Bulk Delete Job that would delete the Scheduled Job records (based on whatever criteria) on the specific date, time, and recurrence you want.
- This method is a little old school before we had things like Azure and Power Automate, but can still work using a CRM-only approach.
- Azure Function
- Creating a timer Azure Function allows you to set a specific recurrence for the process to run, and you can write all of the code within the Azure Function to calculate the date difference. The benefit of an Azure Function is that the process would be decoupled from CRM and run within Azure, thus not taking any resources from the CRM system. The downside is that it requires development and a lot of initial setup (and potential cost) to run this.
- Power Automate
- As you stated, Power Automate (AKA MS Flow) should be used for this sort of process, as it allows us to configure the process via a point and click builder and still set the recurrence for the process. Similar to Azure, the process would run outside of CRM thus not affecting any of the resources for the system.
Here is a screenshot for the Power Automate:
In this example, the formula to calculate the Date Difference would be:
div(sub(ticks(items('Iterate_through_Contacts')?['msdynce_expectedcompletiondate']), ticks(items('Iterate_through_Contacts')?['createdon'])), 864000000000)
This was found from the following blog:
Date Difference in Power Automate
If you have any questions please let me know!
Thanks!
Matt Bayes