
Introduction
If you read my previous post, you will know that there was an issue - the cached phone call details were showing up irrespective of which account I was looking at. We will see what needs to be done to prevent that from happening. So if you are creating a phone call record for Account A, and switch to Account B, the cached data will not show up. If you enter details for a phone call record for Account B and go back to Account A, you will see the cached data for the phone call that you were creating for Account A (and similarly for Account B).
The setup
To make this happen, we will change the properties that we had set in the previous post as following:
-
- OnVisible of the screen (or the OnEndTimer of a 1 second timer)
LoadData( colPhoneCalls, "colPhoneCalls", true ); ClearCollect( colPhoneCallsCurrentAccount, Filter( colPhoneCalls, Regarding.Account = [@ModelDrivenFormIntegration].Item.Account ) ); If( CountIf(colPhoneCallsCurrentAccount, true) = 0, UpdateContext({locCurrentAccountCount: 0}), UpdateContext({locCurrentAccountCount: 1}) ); - In the OnChange and Value fields of each data card of the form that I want to load from cache, I am using the following code (using the Subject datacard as an example here)
- OnChange
If( locCurrentAccountCount = 0, Collect( colPhoneCalls, { Subject: Self.Value, Regarding: [@ModelDrivenFormIntegration].Item } ); UpdateContext({locCurrentAccountCount: 1}), Patch( colPhoneCalls, LookUp( colPhoneCalls, Regarding.Account = [@ModelDrivenFormIntegration].Item.Account ), { Subject: Self.Value, Regarding: [@ModelDrivenFormIntegration].Item } ) ); SaveData( colPhoneCalls, "colPhoneCalls" ); - Value
If( locCurrentAccountCount = 1, LookUp( colPhoneCalls, Regarding.Account = [@ModelDrivenFormIntegration].Item.Account ).Subject, Parent.Default )
- OnChange
- OnVisible of the screen (or the OnEndTimer of a 1 second timer)
With this code, this is how the app behaves:

Conclusion
With a few simple changes, you can make the caching of data smarter to be associated with the account it was created for.
1 thought on “How to add smart offline capabilities in embedded canvas apps”