Select to view content in your preferred language

Arcade Data Expression: expression for gauge stopped working (I did not write the expression), just trying to fix it with no Arcade experience.

2519
12
Jump to solution
08-20-2024 03:43 PM
Labels (2)
Jrpeterson2228
Occasional Contributor

We have a Dashboard that helps the crews determine how many sites have been inspected for the calendar year and which sites remain that require a inspection for the calendar year. the first part of the expression (FIND INSPECTIONS FOR CURRENT YEAR), all up to the Console function works (console log picture), it identifies the sites, by unique identifier (FeatureIDN) that have a recorded inspection for the calendar year. 

There seems to be something wrong or missing from the second part of the expression (FIND SITES THAT HAVEN'T BEEN INSPECTED), where it is supposed to compare CURRENT YEAR inspections and compare FeatureIDN of inspection and compare to the layer that has all the sites unique ID (IDN) and select the sites that have yet to be inspected. 

I receive the following error: Test execution error: Cannot read properties of null (reading 'toString'). Verify test data.

I know that the console output is null, it just shows that the first part is working. I did not create the dashboard, my incumbent did, in 2022, it was brought to my attention about 2 weeks ago that it was not working (just the gauge and table that are linked to this data expression).Data Source Error.jpg

I have recreated the dashboard in hopes to find an error somewhere, also to learn. For the life of me I cannot figure it out, any help will be welcome and very appreciated. I have also attached a picture of when the dashboard worked prior to taking the position. Thank you in advance! The data expression is as follows:

//our URL
var p= Portal("https://olympiawa.maps.arcgis.com");

//FIND INSPECTIONS FOR CURRENT YEAR (Table Data: swInspSystemSite)
//itemID:(e29449b0af064a5c9222d32e81c64fc1) and layer number found in web map properties (https://gis.olympiawa.gov/arcgis/rest/services/Secure/swSystemSiteInspectionsEditable/FeatureServer/24), information, source layer link
var tbleInsp = FeatureSetByPortalItem(p,'e29449b0af064a5c9222d32e81c64fc1', 24, ['FeatureIDN', 'created_date']);
var currentYear = Date(Year(Now()), 00, 01)
var filterInsps = "created_date >= @currentYear";
var insps = Filter(tbleInsp, filterInsps); 

var arrID = []; //[FeatureIDN, created_date]
var arrIndex = 0;
for (var i in insps) {
    arrID[arrIndex]= i.FeatureIDN
    ++arrIndex
}
Console(arrID)

////FIND SITES THAT HAVEN'T BEEN INSPECTED (Feature Layer Data: swSystemSite)
//itemID:(e29449b0af064a5c9222d32e81c64fc1)and layer number found in web map properties (https://gis.olympiawa.gov/arcgis/rest/services/Secure/swSystemSiteInspectionsEditable/FeatureServer/15), information, source layer link
var layerSites = FeatureSetByPortalItem(p, 'e29449b0af064a5c9222d32e81c64fc1', 15);
var filterSites = "IDN NOT IN @arrID AND SiteType <> 'pub'";
var sites = Filter(layerSites, filterSites);
return(sites)

                                                                                

0 Kudos
12 Replies
KenBuja
MVP Esteemed Contributor

I'm not sure why it's not working without looking at the data. The sql statement should work properly. That fact that it stopped working recently could mean there was a change to the underlying data, which is why I was asking if the layer is the correct one and if the fields are present in that layer.

0 Kudos
Jrpeterson2228
Occasional Contributor

Thank you, I will look into the data. I'm not sure what the issue is. Once again, thank you.

0 Kudos
Jrpeterson2228
Occasional Contributor

Issue Solved: The related table, for some reason, had a null value in the FeatureIDN field. This was throwing the error when the expression was trying to execute line 22. I added a value into the table that was null, expression worked. Thank you

0 Kudos