So I have a recurring issue that I am trying to solve. It isn't difficult to fix; it is just a bit annoying.
What I have is code in the OnVisible section of a loading screen for an offline-capable app. I have the code sectioned in four main groups: initial values that need to be set, local data load, the collection of missing tables if a data connection exists (primarily for the initial setup of the app), and collection/initialization of any other values needed before the app fully launches.
When I edit a code in this area (which happens a lot as I am in the process of building it now), I will occasionally get errors in two areas: the initial load of a local table and the attempt to collect that table if it does not exist. Here is a section of that code with the offending areas highlighted in red:
// Initial setup
...
// Load local data
// Load data related to color settings
UpdateContext({LoadMessage: "Loading local data"});
Concurrent(
LoadData(AppColorSchemeCollection, "LocalAppColorScheme", true),
LoadData(AppIndicatorColorCollection, "LocalAppIndicatorColor", true),
LoadData(ColorSchemeCollection, "LocalColorSchemeCollection", true), // <- Error here
LoadData(IndicatorColorCollection, "LocalIndicatorColorCollection", true)
);
UpdateContext({LoadProgress: LoadProgress + 4});
...
// If no color settings exist, create them
// ColorScheme
If(
IsEmpty(ColorSchemeCollection), // <- Error here
UpdateContext({LoadMessage: "Collecting local color schemes"});
Collect(ColorSchemeCollection, 1); //<- Error here
SaveData(ColorSchemeCollection, "LocalColorSchemeCollection") // <- Error here
);
Set(ColorScheme, First(ColorSchemeCollection).Value);
UpdateContext({LoadProgress: LoadProgress + 1});
// IndicatorColor
If(
IsEmpty(IndicatorColorCollection),
UpdateContext({LoadMessage: "Collecting local color schemes"});
Collect(IndicatorColorCollection, 1);
SaveData(IndicatorColorCollection, "LocalIndicatorColorCollection")
);
Set(IndicatorColor, First(IndicatorColorCollection).Value);
UpdateContext({LoadProgress: LoadProgress + 1});
...
// Code ends
What is happening is that I am initializing and saving a singular value (which references the ID of a table of color options) and putting it in a global variable to avoid using a nested LookUp to reference this value. The user can choose another value when using the app, which is saved locally so that their color choice on that device persists.
All the errors are stemming from the ColorScheme section statement:
Collect(ColorSchemeCollection, 1);
The specific error is "The function Collect has some invalid arguments. Expected a table or record value."
Fair enough, but if I simply comment out the offending sections of code, save, close, reopen, and uncomment, everything works again until I add something new to the code. And when I do comment the code out, it doesn't throw the same error for the identically coded IndicatorColor section.
So, what am I doing to break this? Is there a better way to save a singular value locally so that I can avoid a LookUp situation? Again, not the worst thing in the world but it would be nice to not have to repeat the comment/save/close/reopen/uncomment loop.