Check IsDirty for a Field in Power Platform
Introduction
In Dynamics 365 and Power Platform Model-Driven Apps, developers often need to determine whether a field has been modified before executing validation logic, triggering business rules, or making external API calls.
What is IsDirty?
The IsDirty property indicates whether a field has been modified by the user.
If a user changes a field value: IsDirty = true
If the field remains unchanged: IsDirty = false
Why Use IsDirty?
Using the IsDirty property provides several advantages:
- Detect field modifications
- Avoid unnecessary processing
- Improve form performance
- Execute conditional business logic
- Validate changes before saving
- Reduce unnecessary API calls
- Improve maintainability of custom scripts
Solution Overview
Typical workflow:
- Form Loads
- User Updates Field
- Check IsDirty
- Value Changed?
- Execute Logic
- Save Record
Syntax
Use the following syntax to determine whether a field has changed: formContext.getAttribute("fieldname").getIsDirty();
Example: formContext.getAttribute("firstname").getIsDirty();
Step 1: Open the Form
Navigate to: Power Apps > Tables > Select Table > Forms > Open Main Form
Step 2: Create a JavaScript Function
Example: function checkFieldDirty(executionContext) { ... }
Step 3: Register the Event
Register the JavaScript function on one of the following events: On Change Event, On Save Event, Custom Command Button, or Ribbon Action
Checking Multiple Fields
You can also check multiple fields simultaneously.
Example: var firstNameDirty = formContext.getAttribute("firstname").getIsDirty();
Real-World Example
Customer Validation Process
Requirement: Run email validation only when the Email Address field changes.
Common Use Cases
Form Validation, API Integrations, Business Logic Execution, Audit Tracking, Save Optimization, Conditional Notifications
IsDirty vs GetValue
Understanding the difference between these methods is important.
GetValue() returns the current value of the field.
GetIsDirty() returns whether the field value has changed.
Best Practices
Check before running logic, use on critical fields, combine with validation, keep scripts lightweight, test different scenarios, and handle null values.
Benefits
Better performance, reduced API calls, improved user experience, cleaner code, enhanced maintainability, and improved scalability.