I've been running into a handful of issues with calculated expressions in forms on the web. These calculations seem to work fine in Field Maps, but not in the Web Editor or Map Viewer. In the Web Editor, I'm getting failed to calculate errors when adding new features. In the Map Viewer, it just spins forever, and the form never loads, whether adding or trying to edit existing features. I've been trying to troubleshoot by logging info to the console, but those messages don't show up in the console in my browser (Chrome) if the field fails to calculate, so that isn't very helpful. I have found that if I remove parts of my code that look at certain fields, I can get it to succeed. I need to check those fields for the calculation to do what it's supposed to do, though. I've tried structuring the code to check if the problem fields are empty before checking their values, or checking if it's an insert operation vs an update. It seems that just having any of the problem fields anywhere in the code, even if it's in a line that shouldn't be executed in a particular situation, causes the failure.
Here is an example of a calculation that fails:
Console('*LOG*STATUS* Edit Type: ' + $editcontext.editType)
Console('*LOG*STATUS* Origin: ' + $feature.origin)
Console('*LOG*STATUS* Deprecation Date: ' + $feature.date_deprecation)
//Console('*LOG*STATUS* Complete Date: ' + $feature.date_complete)
Console('*LOG*STATUS* Invoice Receivable: ' + $feature.invoice_receivable)
Console('*LOG*STATUS* Type A: ' + $feature.type_a)
if ($editcontext.editType == 'INSERT') {
return 'Planned'
} else {
if (Includes(['Reference', 'Existing'], $feature.origin)) {
return $feature.origin
} else if (!IsEmpty($feature.date_deprecation)) {
return 'Deprecated'
//} else if (!IsEmpty($feature.date_complete)) {
// if (IsEmpty($feature.invoice_receivable)) {
// return 'Complete'
// } else {
// return 'Closed'
// }
//} else if (!IsEmpty($feature.type_a) || (!IsEmpty($feature.photo_count) && $feature.photo_count != 0)) {
// return 'Partial'
} else {
return 'Planned'
}
} If I uncomment the parts that check date_complete or photo_count, it will fail when inserting, even though the first part of the if would be true.
Is this a bug, or am I missing something in my code?