How to Set a Dynamics 365 Field Value in Validate Method
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.

- 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.
Ensure you have access to the development environment and are familiar with X++ Chain of Command (CoC) extensions.
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.
Capture the boolean result of the standard validation logic by calling the next method within your Chain of Command extension.
If the validation evaluates to false, assign an appropriate empty value to the field. For example, use "" for strings (e.g., currentMyTable.MyField = "";).
Call the reread() method on your form data source to update the buffer with the latest changes (e.g., formDataSource.reread();).
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();).

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. Visit the website: Go to the official WPS Office website to find the appropriate download for your operating system.
- 2. Download the installer: Click the Free Download button to get the lightweight installation file.
- 3. Install and launch: Run the installer and start drafting your technical specifications and documentation seamlessly.

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.




