Introduction
When working with APIs and data integration in Power Apps, you may come across the term ETag (Entity Tag). ETag plays a crucial role in managing data consistency, handling concurrent updates, and improving performance when interacting with data sources such as Microsoft Dataverse, SharePoint, and custom APIs.
This article explains what ETags are, why they matter, and how they are used in Power Apps.
What is an ETag?
An Entity Tag (ETag) is a unique identifier assigned to a specific version of a record or resource.
Whenever a record is modified, its ETag value changes. This allows applications to determine whether the data has been updated since it was last retrieved.
Think of an ETag as a version number for a record.
Example
Suppose a customer record has the following ETag:
{
"CustomerID": 101,
"Name": "Ketan",
"@odata.etag": "W/\"123456\""
}
If another user updates the customer information, the ETag may change to:
{
"CustomerID": 101,
"Name": "Ketan",
"@odata.etag": "W/\"123457\""
}
The changed ETag indicates that the record has been modified.
Why are ETags Important?
1. Prevent Data Conflicts
In multi-user environments, multiple users may edit the same record simultaneously.
Without ETags:
User A opens a record.
User B updates the same record and saves.
User A saves their older version.
User B's changes are overwritten.
With ETags, the system can detect that the record has changed and prevent accidental overwrites.
2. Optimistic Concurrency Control
ETags enable optimistic concurrency.
Instead of locking records while users edit them, the system checks whether the record has changed before saving updates.
Benefits include:
Better performance
Reduced locking
Improved scalability
Better user experience
3. Improve API Efficiency
ETags can reduce unnecessary data transfers.
Clients can ask:
"Only send me the resource if it has changed."
This minimizes bandwidth usage and improves application performance.
ETags in Power Apps
Power Apps often works with data sources that expose ETags through OData services.
Common examples include:
Microsoft Dataverse
SharePoint
Custom REST APIs
OData-based services
When records are retrieved, the ETag value is typically included in the response.
Example:
{
"@odata.etag": "W/\"789654\"",
"Title": "Project Alpha",
"Status": "Active"
}
ETag in SharePoint Lists
When Power Apps connects to SharePoint, every list item contains an ETag value.
Example:
{
"__metadata": {
"etag": "\"3\""
}
}
Whenever the list item changes:
{
"__metadata": {
"etag": "\"4\""
}
}
The incremented value indicates a newer version of the item.
How Power Apps Uses ETags
Power Apps automatically uses ETags behind the scenes when updating records.
For example:
Patch(
Customers,
ThisItem,
{
Status: "Approved"
}
)
The platform sends the ETag along with the update request to verify that the record has not changed since it was loaded.
If the ETag does not match the latest version, the update may fail with a concurrency-related error.
Handling Concurrency Errors
A common scenario:
User A opens a record.
User B modifies and saves it.
User A attempts to save outdated information.
The ETag mismatch is detected.
Possible error message:
The specified record has been modified by another user.
Recommended Handling
Use error handling functions:
IfError(
Patch(
Customers,
ThisItem,
{
Status: "Approved"
}
),
Notify(
"The record was updated by another user. Please refresh and try again.",
NotificationType.Error
)
)
This provides a better user experience.
ETags with Power Automate
When using Microsoft Power Automate, ETags can be used in HTTP actions.
Example:
If-Match: W/"123456"
The API updates the resource only if the ETag matches the current version.
Benefits
ETag and HTTP Headers
Several HTTP headers work with ETags.
| Header | Purpose |
|---|
| ETag | Returns the current version identifier |
| If-Match | Update only if ETag matches |
| If-None-Match | Return data only if changed |
| If-Modified-Since | Check modification timestamp |
Example:
GET /api/customers/101
Response:
ETag: "123456"
Update request:
PUT /api/customers/101
If-Match: "123456"
Best Practices
Always Handle Errors
Implement error handling using:
IfError()
or
Errors()
Refresh Before Editing
Refresh data before allowing users to edit:
Refresh(Customers)
This helps reduce concurrency conflicts.
Use Dataverse Concurrency Features
When using Dataverse:
Enable optimistic concurrency when appropriate.
Validate records before updating.
Handle version conflicts gracefully.
Avoid Blind Updates
Instead of updating records without validation:
Patch(Customers, ThisItem, Updates)
Ensure users are working with the latest data whenever possible.
Common ETag-Related Errors
| Error | Cause |
|---|
| Precondition Failed (412) | ETag mismatch |
| Conflict (409) | Concurrent modification |
| Record Modified by Another User | Version changed |
| Update Failed | Stale record version |
Real-World Example
Imagine a Help Desk application built in Power Apps.
A support ticket is assigned to an agent.
Agent A opens Ticket #1001.
Agent B changes the ticket status to "Closed".
Agent A attempts to update the priority.
Without ETags:
With ETags:
Power Apps detects the version change.
Agent A receives a warning.
The ticket remains consistent.
This ensures reliable and accurate data management.
Conclusion
ETags are a powerful mechanism for maintaining data consistency in Power Apps and related Microsoft technologies. They help prevent accidental overwrites, support optimistic concurrency, and improve API efficiency.
Key Takeaways
ETag represents a specific version of a record.
ETags change whenever data is modified.
Power Apps uses ETags automatically with supported data sources.
ETags help prevent concurrent update conflicts.
Proper error handling is essential when working with multi-user applications.
SharePoint, Dataverse, and APIs commonly use ETags for version control.
Understanding ETags enables Power Apps developers to build more reliable, scalable, and user-friendly business applications.