logo
search
Others

How to Set a Dynamics 365 Field Value in Validate Method

Chanuka GeekiyanageChanuka Geekiyanage Oct 12, 2026 869 views

Question details

The user needs to clear a field value when validation fails in a form data field validate Chain of Command method in Dynamics 365 Finance and Operations.

How to Set a Dynamics 365 Field Value in Validate Method
Product
Dynamics 365 Finance and Operations
Device & OS
not provided
Scenario
Handling form data field validation failures in D365 using X++.
Observed behavior
A field retains its value or causes an unwanted state when a validation method fails, requiring it to be cleared and refreshed programmatically.
Before you start

Ensure you have access to the development environment and are familiar with X++ Chain of Command (CoC) extensions.

Solution 1Recommended

Clear the Field Value and Refresh Form Data Source

Use this method to programmatically reset the field to an empty value and refresh the UI when validation fails.

When extending the validate method using Chain of Command, you can manipulate the field buffer before returning the validation result.

It is crucial to follow up the variable assignment with a reread and refresh of the data source so the form accurately reflects the empty value to the user.

1
Check validation result

Capture the boolean result of the standard validation logic by calling the next method within your Chain of Command extension.

2
Set the field to an empty value

If the validation evaluates to false, assign an appropriate empty value to the field. For example, use "" for strings (e.g., currentMyTable.MyField = "";).

3
Reread the data source

Call the reread() method on your form data source to update the buffer with the latest changes (e.g., formDataSource.reread();).

4
Refresh the data source

Call the refresh() method on the data source to update the user interface so the cleared field is visible to the user (e.g., formDataSource.refresh();).

Clear the Field Value and Refresh Form Data Source
Data Types Matter: Ensure that the empty value assigned matches the field's data type, such as an empty string for text fields, zero for integers, or dateNull() for date fields.
Free Microsoft Office alternative

Document Your Dynamics 365 Development with WPS Office

While WPS Office does not directly execute X++ code for Dynamics 365, it is an exceptional, free alternative to Microsoft Office for writing technical documentation, drafting code specifications, and managing project spreadsheets. Experience a lightweight suite with high compatibility and a familiar interface.

  1. 1. Visit the website: Go to the official WPS Office website to find the appropriate download for your operating system.
  2. 2. Download the installer: Click the Free Download button to get the lightweight installation file.
  3. 3. Install and launch: Run the installer and start drafting your technical specifications and documentation seamlessly.
Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx).Easily format and document X++ code snippets and Dynamics 365 technical designs.Lightweight installation with a user-friendly, familiar interface for developers.Free to use, reducing software overhead for freelance developers and IT teams.
microsoft office alternative - wps office

Frequently Asked Questions

Why is the field value not updating on the form after I clear it in code?

If you only change the field buffer in your X++ code (e.g., table.Field = "";), the user interface will not automatically reflect the change. You must call formDataSource.refresh() and sometimes formDataSource.reread() to push the code changes to the visual form.

Can I use Chain of Command (CoC) to bypass standard field validation?

Yes, but you must always call the next method in your CoC extension. You can evaluate its result and add custom logic—like clearing the field or changing the return value—if the standard or custom validation fails.

What is the correct way to empty a date field in Dynamics 365 X++?

To clear a date field in X++, you should use the dateNull() function instead of assigning a blank string or zero. For example, use myTable.MyDate = dateNull(); to properly reset the value.