A common scenario that we consultants are asked to solution is the need to notify or create records in preparation of an event or task. In today’s blogpost, we’ll walk through a scenario in which we’ve been asked to create an Annual Review record one month before the Account’s Fiscal Year Start Date. Enjoy!

flow

Typically, with these types of solutions we need to utilize an ETL tool, such as Scribe or the KingswaySoft Dynamics 365 Adapter for Microsoft Dynamics SSIS – or by leveraging a Wait condition in a workflow. However, we can also solve this with Microsoft Flow using a Scheduled Flow.

To prepare for the solution, we created a custom Annual Review entity with a look up to the Account, as well as a Review Date field. Next, we create a custom date field – named Fiscal Year Start Date – on the Account Record. For this field, we specifically set the Behavior to Date Only, as it will not store the time, which will be critical in the Flow design.

Once we have the CRM fields in place, we are able to leverage Flow. We will start by creating a Scheduled Flow that will run on the first of every month at 10 AM:

Build a scheduled flow 
Flow name 
Create Review Task 
Run this flow • 
Starting 
Repeat every 
This flow will run: 
Every month 
Stay on top of what's important without the effort—you choose 
when and how often the flow runs. 
Examples: 
Automate team reminders to submit expense reports 
Auto-backup data to designated storage on a regular basis 
7/1/14 at 
Month 
Skip 
Cancel

The first step of the Flow will utilize the Initialize Variable action, which will identify the date value we need for the next step in the Flow. In order to identify the proper date value for our example, we need to identify the first date of the month following when the flow is run. For example, if it runs on July 1, we expect the result to be August 1. We used the following code:

startOfDay(startOfMonth(addToTime(utcNow(),1, ‘Month’)))

Let’s step through how the action is modifying current date to get the value we are looking for:

  1. Adds a month to the current date
  2. Identifies the first date in that month
  3. Sets the time component of the Datetime to 00:00:00.000

Note: This code will work on any date during the month, thereby giving us the ability to run manually if an issue arises during the normal schedule.

Using the Date variable from the first step, we identify the records within Dynamics that fit that criteria. In other words, it shows us any Accounts for which the Fiscal Year Start Date = August 1.

From here, we will add a Dynamics Create a New Record action that will automatically wrap the action in an Apply to Each function. In other words, it will run the Create a New Record action for all the records identified in the previous List records functionality. The Create a New Record action will create an Annual Review record, assigning the Owner of the record as the owner of the Account, the Due Date to the Fiscal Date variable, and Account to the Account identified in the List records action.

Machine generated alternative text:
Apply to each 
* Select an output 
from previous steps 
value x 
Create a new record (Preview) 
O 
*Organization Name 
*Entity Name 
Account 
Account 
Import Sequence 
Number 
Name 
Owner 
Owner Type 
Record Created On 
Review Date 
PowerObjectsPowerAppsDemos 
Annual Reviews 
Account x 
Sequence number of the import that created this record. 
The name of the custom entity. 
Owner x 
systemusers 
Date and time that the record was migrated. 
Fiscal Year Start Date x

Note: We could have performed many different actions instead of creating the Annual Review record. For example, we could have done the following:

  • Create a Dynamics 365 Activity record (Task, Email, Phone Call, etc.)
  • Send an email directly to the owner of the account.

Using Flow in this capacity is a great way to perform time-based activities, without using an ETL tool, such as Scribe or KWS and SSIS – or by leveraging a Wait condition in a workflow.

Hopefully this helps you see the ease of automating processes with Microsoft Flow. Don’t forget to subscribe to our blog for more Dynamics 365 and Flow tips.

Happy Flowing!

Avatar for Joe D365

Joe D365

Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.