Create Month or Year Only Field in Dynamics 365

By | December 6, 2017


A lot of time we come across the situations where we would need to have one field to store just the Month part of the date and another one to store the Year part of the date. For example, Credit or Debit Card validity period where the user has to select Month and Year. In such cases, we could create one optionset field with options to select Month and number field to enter the year. In some scenarios, we create one Date only field and write a script or workflow to take the month and year part out from the selected date and store it in a separate Month and Year fields.

We have now found a better approach to tackle this kind of situation.

We can use the ‘Auto-Complete’ control for this purpose. The Auto-Complete control was introduced in Dynamics CRM 2016. This control provides suggestions to the user as soon as the user starts typing in the text fields.

Refer this article to know more about Auto-Complete control introduced in Dynamics CRM 2016.

Steps to create a Month and Year only fields using the Auto-Complete control:

1. First, create two text fields namely, ‘Month’ and ‘Year’.

2. Place these two fields on the entity form

Create Month or Year Only Field in Dynamics CRM

3. Now, write a script to make these two fields act as an autocomplete and bind month and year collection to Month and Year field respectively.

Month collection:

Year collection :

This list is going start from the last two years from the current year and will end with next 15 years from the current year.

For example, if the current year is 2017 then the autocomplete suggestion list will show the list years start from 2015 to 2024. You can use your own logic to create the year list.

4. Call suggestMonth function on a load of form.

 5. Call suggestYear function on load of form.

6. This way our standard text fields becomes auto-complete fields and will start showing the suggestion for month and year as soon as user starts typing as seen in the screenshot below;


Create Month or Year Only Field in Dynamics CRM


Create Month or Year Only Field in Dynamics CRM

7. Then finally add the validation code on change of these two fields so that the user cannot enter values other than the values present in the auto-complete list.

Create Month or Year Only Field in Dynamics CRM

Note: Supported versions of this solution are CRM 2016 and above.


Using the above-mentioned steps, the user can make use of auto-complete control feature of Dynamics 365 to create Month and Year only field.

QuickBooks and Dynamics CRM Integration

Leave a Reply