Skip to main content
Community site session details

Community site session details

Session Id :

How to Use setIsValid in Dynamics 365 for Effective Field Validation

Inogic Profile Picture Inogic 1,043 Super User 2025 Season 1

In Dynamics 365, JavaScript plays a crucial role in customizing forms and enhancing the user experience. One useful function in D365 form scripting is “setIsValid()”, which allows developers to control field validation dynamically.

In this blog post, we’ll explore a real-world business use case for “setIsValid()” and demonstrate how it can improve data integrity and user workflows.

Understanding setIsValid()

The “setIsValid()” function is used to manually set the validation state of a field in a D365 form. By default, fields are validated based on required rules, but sometimes, business logic requires conditional validation.

Syntax:  formContext.getAttribute("fieldname").setIsValid(bool, message);

bool (Boolean): Set this to true if the field passes validation, or false if it fails.

message (String, optional): An error message displayed if validation fails.

Business Use Case: Conditional Field Validation in Opportunity Form

Scenario: 

A sales organization wants to ensure that the "Estimated Revenue" field in an Opportunity record is mandatory only if the "Probability" field is greater than 50%. Otherwise, the field should remain optional.

Step by Step Implementation: 

1. Add JavaScript to the Opportunity Form

Create a JavaScript web resource and add it to the Opportunity form’s `OnChange` event for the Probability field...Read More>>

Comments