You can easily compare a date stored in Dataverse (Dynamics 365) with the current date by placing a condition in Word and applying proper formatting. This can be useful for a variety of cases, such as for tracking deadlines and due dates, monitoring performance, and generating reminders.
Define the condition
First, you need to set up a condition in Word. The condition in our example should be as follows: If the due date of a record is greater (>) than the current date, show active, else show expired. It should appear like this in your template:
{ IF [Due Date] > [Current Date] “Active” “Expired” }
To create this condition, navigate to the Insert tab in Word, and then to Quick Parts > Field and follow the following steps.
Select IF from the left-hand bar, then type “Active” and then “Expired”.
Press “Alt + F9” on your keyboard to show the field codes instead of their values. You can also do this by navigating in Word to File > Options > Advanced and then scroll down and check “Show field codes instead of their values.”
Delete everything in the brackets after “Expired”. The following should then be shown on your Word document:
{ IF > “Active” “Expired” }
Insert and format the Dataverse field
Place your mouse between IF and >. Then navigate to the Template Designer and expand the Insert Field dropdown menu. Select Insert Computed Item > DateTime Field.
Select the date-field you want to insert, which in this example is the Due Date of a quote. Then set the date format and culture.
Please note: It is very important that you set the same date format and culture for both the Due Date and the Current Date, so that they can be compared in the IF condition.
For example, you can choose to define the date format as the day, month, then year. This would look like dd.MM.yyyy, which could be shown as 13.02.2024.
Insert and Format the Current Date
The following should now be shown on your Word document:
{ IF Due Date > “Active” “Expired” }
Now place your cursor between > and “Active”. Expand the Insert Field dropdown again, but this time select Insert Computed Item > Advanced String. Follow the steps for formatting the current date, as described here. For this example, the placeholder text will be set as Current Date.
Important: The date format and culture must be the same as the Due Date.
When done, the following should be shown on your Word document:
{ IF Due Date > Current Date “Active” “Expired” }
Test the Condition
Select Choose Data from the mscrm-addons tab in Word and select a sample record.
Your result will return either Active or Expired, depending on whether or not the Start Date is greater than the Current Date. Below you can see the starting condition, then the result with the field codes shown, and lastly you can see the result where the value instead of the field codes is shown.
That’s it! We appreciate your feedback! Please share your thoughts by sending an email to support@mscrm-addons.com.