Offline
This post is the sixth in a series that started with https://maximoplus.com/blog/getting-started-with-maximoplus/ .
MaximoPlus supports the reading and writing of Maximo data in the offline mode. To enable the offline mode on the application, add the offlineenabled property on the application container, for example:
<AppContainer
mboname="po"
appname="po"
id="pocont"
offlineenabled={true}
/>
The app with the enabled offline mode will automatically set up the database on the device.
Try setting the property as above in your example application and then deactivate the network connection on your device (note: in Expo development mode, you need to connect your device via USB or run the app in Emulator). If you perform any change while in offline mode, the data changes will be sent automatically to the server once you go online again.
Offline Lists
MaximoPlus stores the list items to offline storage when you open the list. To pick the value from that list while offline, you need to specify the offlineReturnColumn attribute in the column's metadata. The offlineReturnColumn is a list column that will be copied from the list once the user picks the row. Maximo does it automatically in the online mode, but we need to set it explicitly for the offline:
metadata={{
SHIPVIA: {
hasLookup: "true",
listTemplate: "valuelist",
filterTemplate: "valuelist",
offlineReturnColumn: "VALUE"
}}
By default, MaximoPlus stores offline only the data that has been visited by the user. That means that if you opened the list while online, it would store just the rows you had seen on the list. If you want to store all the items from the list, you need to add the preloadOffline attribute in metadata:
metadata={{
SHIPVIA: {
hasLookup: "true",
listTemplate: "valuelist",
filterTemplate: "valuelist",
preloadOffline: "true",
offlineReturnColumn: "VALUE"
}
}}
Be careful when using this option because a value list may contain a vast number of elements, and storing all of them offline will be a time-consuming process with an increased load on the server.
Preloading the offline data
If you have a use case that a user needs to have the complete set of data available offline, you need to use the preloadOffline API function. This function stores all the data defined by the filter criteria of the AppContainer and automatically loads the data for all the related containers as well. Here is the example of an action that preloads all the POs with the status WAPPR:
const preload = () => {
setQbe("pocont", "status", "wappr")
.then(() => reload("pocont"))
.then(() => preloadOffline());
};
This is the final post in the Getting Started series. Feel free to play with and make changes to the template, and let us know what you think.