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.

829
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
1 Solution

Accepted Solutions
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

View solution in original post

0 Kudos
12 Replies
KenBuja
MVP Esteemed Contributor

Since your data isn't public, do the fields "IDN" and "SiteType" exist in layerSites?

0 Kudos
Jrpeterson2228
Occasional Contributor

Yes, they live in a feature service layer.

0 Kudos
KenBuja
MVP Esteemed Contributor

Have you checked whether layerSites is returning the correct layer?

0 Kudos
Jrpeterson2228
Occasional Contributor

I apologize in advance, I a very new to this. I'm not sure I know if it returning the correct layer or not.

0 Kudos
KenBuja
MVP Esteemed Contributor

You can return the layer to make sure it's the correct one (and click Run in the upper left corner instead of Done in the lower right corner in the data expression editor)

var layerSites = FeatureSetByPortalItem(p, 'e29449b0af064a5c9222d32e81c64fc1', 15);
return layerSites

 

Jrpeterson2228
Occasional Contributor

It worked, thank you so much! Where or what do recommend for me to practice or learn more about Arcade? Once again, THANK YOU!

0 Kudos
KenBuja
MVP Esteemed Contributor

I'm not sure that solved your problem, since it's not returning the filtered data set. That was just to make sure that the dataset that is being returned is the one you're expecting. You still have to figure out why the filter isn't working (line 23)

You can start here to learn about the fundamentals of Arcade. You can also view some technical sessions from last year's User Conference. I'm not sure if this year's sessions are available yet.

0 Kudos
Jrpeterson2228
Occasional Contributor

You are correct, the filter is not working...

0 Kudos
Jrpeterson2228
Occasional Contributor

Any suggestions on why the filter isn't working, or reference material I can use to troubleshoot? Thank you for helping.

0 Kudos