Testing data from FileMaker
I mentioned this in a recent #Office Hours time and wanted to post it here in the community. When FileMaker data comes into the web viewer, into the JS, it is a great idea to test out the data to make sure that FileMaker passed it in correctly.
I used AI but also wrote most of this myself :) Read through the code and decipher it.
// Get the progress value from the FileMaker data
// Default to 0 if no value is provided
let progressValue = 0;
// Just expect a direct number value now
// FileMaker will pass data as { "data": 75 } or just the number directly
if (obj !== undefined) {
if (typeof obj === "number") {
// Direct number passed
progressValue = obj;
} else if (obj.data !== undefined && typeof obj.data === "number") {
// Number in data property
progressValue = obj.data;
} else if (typeof obj === "string" && !isNaN(parseFloat(obj))) {
// String number passed
progressValue = parseFloat(obj);
}
}The idea in this code it to make sure that the data, in this case a number, can be used in the progress bar widget. JS can be less forgiving of data types: A number is a number and a string is a string.
In the above code the data from FileMaker is run against some checks to see what kind of data came in. It could be a number, a value inside an object, or a string. I’m using the undefined and typeOf JS methods to check the type and then handling it appropriately:
First I check if the value is not undefined (that is, I’m making sure something is coming in from FileMaker)
If that’s the case, then we check the type of the object to see if it is a number.
If it is not a number, we check to see if the data is a typeOf object and then pull out the ‘data’ property
If it is not a number or an object, then we see if it is a string and convert it to a number.
These extra lines will solve a lot of bugs right away, so it is worth exploring.