As the maker of the app, you have to set up everything to do with working with collections, data sources, and any offline saving/retrieving of data.
Your code above references a collection (ColInventaire) and an external data source (Inventaire). It is saving data from the collection as new records to the external data source. I don't know the overall user experience and process of your app, but what should happen here if the user is not connected to the internet? Instead of using Patch() to save the collection records, should you instead save that data to the device? If so, I would structure it more like this:
If(CountRows(ColInventaire) > 0;
If(Connection.Connected;
ForAll(ColInventaire;
Patch('Inventaire'; Defaults('Inventaire');
{ // Insert your Patch records here
}
)
);
SaveData(ColInventaire;"MyData")
)
);;
Clear(ColInventaire);;
This code saves the data when there is no internet connection to complete a successful Patch(). Most importantly, it saves the data before Clear() erases the collection. This code only saves the data; it does not automatically Patch() it back to the external data source once an internet connection is reestablished - you will need to set that up.
Only collections can be saved using the SaveData() function and you will need to decide which logical points in your app you need to save (and later load) data.
Hope that helps,
Bryan