Citizen Developer
Timespan
explore our new search
​
How to build Dataverse Offline Mode (Canvas Apps) and Implement Concurrency
Image Source: Shutterstock.com
Microsoft Dataverse
Nov 30, 2023 10:00 AM

How to build Dataverse Offline Mode (Canvas Apps) and Implement Concurrency

by HubSite 365 about Temmy Wahyu Raharjo

Citizen DeveloperMicrosoft DataverseMicrosoft DataverseLearning Selection

Master Dataverse Offline: Canvas App Concurrency Solutions & Tips

Temmy Wahyu Raharjo recently shared insights on implementing offline mode and concurrency in Dataverse Canvas Apps. The author's curiosity was sparked by how the system handles concurrent updates and strict concurrency enforcement. 

The author began by configuring the table for offline use, enabling the Audit Log, and setting up the Canvas App following practices established They tested the system's default behavior by attempting concurrent record updates from two disconnected devices and then examined the audit history after reconnecting to the internet. The system did not block simultaneous updates, highlighting a need for further solutions.

 

To handle this issue, a plugin was envisioned, inspired by previous attempts before the advancements in Canvas Apps. A new text column, 'Row Version,' was crafted, and corresponding Canvas App commands were adjusted. These changes aimed to introduce a system where updates would be verified for their version correctness before being accepted.

  • Insight into system behavior was sought by logging pertinent values.
  • The creation and implementation of a plugin to verify version data was pursued.
  • Two test scenarios were run, revealing that updates were regulated, and only the first change was honoured.
  • Lack of visible error notifications in the app, despite errors being logged in the Plugin Trace Logs, was noted.

To address this, Raharjo explained how to create a plugin to manage concurrency. This solution involves adding a new text column to store the record's Row Version and adjusting the Canvas App to pass the Version Number to the plugin for validation. By logging the values, Raharjo noticed how the system behaves with updates, which influenced the plugin's development process.

The code for the plugin, designed to ensure data integrity during concurrent updates, uses the Dataverse SDK for validation and error handling. If submitted data doesn't match the stored Row Version, the plugin identifies a conflict and throws an error. This plugin offers a robust method to manage concurrency issues not inherently handled by Dataverse's offline mode.

Testing the plugin with different scenarios—updating records on two devices offline and then reconnecting, or making simultaneous updates—demonstrated that it only permits the first update, maintaining data consistency. Even if errors occur when updating offline, the plugin trace logs capture these, providing a reliable method of oversight.

The blog post concludes by highlighting the importance of managing updates in Canvas Apps, especially when working with offline capabilities. Management of concurrent updates through custom plugins assures data accuracy and robust conflict resolution, an essential aspect of any reliable mobile application utilizing Microsoft Dataverse.

Developing Offline-Capable Canvas Apps

Mobile users often need to be productive even when they have limited or no connectivity. When you build a canvas app, you can perform tasks like opening Power Apps Mobile and running apps offline. It's possible to determine when an app is offline, online, or in a metered connection using the Connection signal object. Additionally, you can use collections and leverage the LoadData and SaveData functions for basic data storage when offline.

Offline capability is now integrated with the preview of offline-first experience for apps based on Microsoft Dataverse. This capability, however, is only available while running the apps using the native Power Apps Mobile players on iOS, Android, and Windows. It's important to note that canvas apps running in web browsers cannot run offline, even when using a web browser on a mobile device.

For canvas apps in Teams, the data limit through the LoadData and SaveData functions is 1 MB. This limit is suitable for a small number of text strings, numbers, and dates, but not for images or other media. An example using Twitter data is included in the LoadData and SaveData function reference, illustrating a scenario that doesn't require a connection.

Limitations

The LoadData and SaveData functions form a simple mechanism to store small amounts of data on a local device, limited by the available app memory. These functions operate on an in-memory collection, and the available memory varies depending on the device, operating system, and the complexity of the app. Testing your app with expected scenarios on the intended devices is crucial, especially if you plan to store more than a few megabytes of data.

These functions do not automatically resolve merge conflicts when a device comes online. The configuration of what data is saved and how reconnection is handled is up to the app maker. For updates on offline capabilities, it's recommended to return to this topic and subscribe to the Power Apps blog.

Offline Connections for Power Apps

When designing offline scenarios, consider how your apps work with data. Apps in Power Apps access data through connectors like SharePoint, Office 365, and Microsoft Dataverse, or custom connectors for services with a RESTful endpoint. These connectors use HTTPS over the Internet, requiring users to be online to access data and other service capabilities.

In Power Apps, you can filter, search, sort, aggregate, and manipulate data in a consistent way across various sources. For offline scenarios, local collections are used for data management, enabling almost no changes to an app's logic.

Build an Offline App

To illustrate the offline aspects of app development, let's consider a simple scenario focused around Twitter. You'll build an app to read and submit tweets while offline. When online, the app will post tweets and reload the local data. The app will perform tasks like fetching data through the Twitter connector when online, or loading data from a local cache using the LoadData function when offline. Users can submit tweets, and every five minutes while the app is online, it posts any tweets in the local cache and refreshes it using the SaveData function.

The steps to build this app include adding Twitter to a blank phone app, collecting existing tweets, showing tweets in a gallery, displaying connection status, adding a box to compose tweets, and adding a button to post the tweet. Additionally, you'll need to check for new tweets using a Timer control.

Understanding Microsoft Dataverse's Offline Capabilities

Microsoft Dataverse offers robust offline capabilities, particularly for Canvas Apps, that enable users to work without an internet connection. Ensuring data consistency during these periods of disconnection, especially when multiple users attempt to update the same records, requires careful management. The default system behavior does not prevent concurrent updates, which might lead to data conflicts. By creating custom plugins, we can implement a layer of concurrency control, maintaining data integrity across the system. Logging and validating changes against a Row Version ensures that only the first update goes through, preventing conflicts. This approach is vital for organizations that rely on accurate and up-to-date information across their Canvas Apps.

Exploring Offline Capabilities and Data Concurrency in Business Apps

Offline capabilities and data concurrency are crucial in ensuring data integrity and user experience in today's mobile-first business environment. Microsoft Dataverse offers tools to build robust offline modes in Canvas Apps, enabling apps to function seamlessly without a constant internet connection. Handling and mitigating concurrency conflicts is a key aspect, requiring thoughtful implementation of version control and error handling. By leveraging plugins and consistent versioning, developers can ensure that changes are synchronized correctly when the app goes online, keeping the user data consistent across devices and sessions. These features contribute to making Microsoft Dataverse a reliable platform for developing resilient business applications.

Read the full article Learning Dataverse Offline Mode (Canvas Apps) and Implement Concurrency

Summary

Developing offline-capable canvas apps enables mobile users to remain productive even without a stable internet connection. By utilizing Power Apps Mobile, you can build apps that function offline using tools like the LoadData and SaveData functions. These functions are vital for managing data in offline scenarios but come with limitations such as memory constraints and the lack of automatic conflict resolution. Understanding these limitations and the process of building offline apps, especially with data handling and synchronization, is crucial for effective app development.

Microsoft Dataverse - Master Dataverse Offline & Concurrency in Canvas Apps

Keywords

Dataverse Offline Mode, Canvas Apps Offline, Implement Concurrency Control, Dataverse Canvas Apps, Offline Data Synchronization, Mobile Offline Dataverse, Concurrency in Dataverse, Offline Capabilities PowerApps, Dataverse Offline Data, PowerApps Canvas Offline Concurrency