Hello,
I made a dashbaord awhile ago with two data expressions that were functioning fine, and now both are giving me the same error "Test execution error: Cannot read properties of null (reading 'toString'). Verify test data."
If anyone notices something amiss or knows what would have changed to now get an error please let me know!
var portal = Portal("https://www.arcgis.com");
var fs = FeatureSetByPortalItem(
portal,
"1327308ab2d1487490ec7d5e08fb36ec",
1,
["Species", "Other_Species", "Project_Site", "total_volume_oz", "Size_ac", "Product_Name1", "product_amount_oz1","Product_Name2", 'Surfractant_name', 'surfractant_amount_oz', 'product_amount_oz2'],
false
);
var sites = Distinct(fs, ["Project_Site"]);
var features = [];
for (var site in sites) {
var siteName = site["Project_Site"];
var siteRecords = Filter(fs, "Project_Site = @siteName");
var totalVol = Sum(siteRecords, "total_volume_oz");
var totalAc = Sum(siteRecords, "Size_ac");
// Build unique species list — only distinct values from CSV fields
var speciesSet = {};
for (var rec in siteRecords) {
var sp1 = rec["Species"];
var sp2 = rec["Other_Species"];
if (!IsEmpty(sp1)) {
var parts1 = Split(sp1, ",");
for (var i = 0; i < Count(parts1); i++) {
var val = Trim(Replace(parts1[i], "_", " "));
if (!IsEmpty(val)) {
speciesSet[val] = true;
}
}
}
if (!IsEmpty(sp2)) {
var parts2 = Split(sp2, ",");
for (var j = 0; j < Count(parts2); j++) {
var val2 = Trim(Replace(parts2[j], "_", " "));
if (!IsEmpty(val2)) {
speciesSet[val2] = true;
}
}
}
}
var speciesList = [];
for (var k in speciesSet) Push(speciesList, k);
speciesList = Sort(speciesList);
var allSpecies = Concatenate(speciesList, ", ");
// Build unique product list
var productsSet = Distinct(siteRecords, ["Product_Name1"]);
var productList = [];
for (var p in productsSet) {
var prod = p["Product_Name1"];
if (!IsEmpty(prod)) Push(productList, Replace(prod, "_", " "));
}
var allProducts = Concatenate(productList, ", ");
Push(features, {
attributes: {
Project_Site: siteName,
total_chemical: totalVol,
total_ac: totalAc,
all_species: allSpecies,
products_used: allProducts
}
});
}
// Use Dictionary() directly — this works in popups and Dashboards
var tableDict = {
fields: [
{ name: "Project_Site", type: "esriFieldTypeString", alias: "Project Site" },
{ name: "total_chemical", type: "esriFieldTypeDouble", alias: "Total Chemical (oz)" },
{ name: "total_ac", type: "esriFieldTypeDouble", alias: "Total Area (ac)" },
{ name: "all_species", type: "esriFieldTypeString", alias: "All Species" },
{ name: "products_used", type: "esriFieldTypeString", alias: "Products Used" }
],
geometryType: "", // no geometry
features: features
};
// Return as FeatureSet
return FeatureSet(tableDict);
Hey @EmilyLopez
This is more than likely due to a null value being present and .string() attempting to make it a string, which isn't possible in this case, try to add some null checks and you may have some more luck:
var portal = Portal("https://www.arcgis.com");
var fs = FeatureSetByPortalItem(
portal,
"1327308ab2d1487490ec7d5e08fb36ec",
1,
["Species", "Other_Species", "Project_Site", "total_volume_oz", "Size_ac", "Product_Name1", "product_amount_oz1","Product_Name2", 'Surfractant_name', 'surfractant_amount_oz', 'product_amount_oz2'],
false
);
var sites = Distinct(fs, ["Project_Site"]);
var features = [];
for (var site in sites) {
var siteName = site["Project_Site"];
var siteRecords = Filter(fs, "Project_Site = @siteName");
var totalVol = Sum(siteRecords, "total_volume_oz");
var totalAc = Sum(siteRecords, "Size_ac");
// Build unique species list — only distinct values from CSV fields
var speciesSet = {};
for (var rec in siteRecords) {
var sp1 = rec["Species"];
var sp2 = rec["Other_Species"];
if (!IsEmpty(sp1) && sp1 != null) {
var parts1 = Split(sp1, ",");
for (var i = 0; i < Count(parts1); i++) {
var val = Trim(Replace(parts1[i], "_", " "));
if (!IsEmpty(val)) {
speciesSet[val] = true;
}
}
}
if (!IsEmpty(sp2) && sp2 != null) {
var parts2 = Split(sp2, ",");
for (var j = 0; j < Count(parts2); j++) {
var val2 = Trim(Replace(parts2[j], "_", " "));
if (!IsEmpty(val2)) {
speciesSet[val2] = true;
}
}
}
}
var speciesList = [];
for (var k in speciesSet) Push(speciesList, k);
speciesList = Sort(speciesList);
var allSpecies = Concatenate(speciesList, ", ");
// Build unique product list
var productsSet = Distinct(siteRecords, ["Product_Name1"]);
var productList = [];
for (var p in productsSet) {
var prod = p["Product_Name1"];
if (!IsEmpty(prod) && prod != null) Push(productList, Replace(prod, "_", " "));
}
var allProducts = Concatenate(productList, ", ");
Push(features, {
attributes: {
Project_Site: siteName,
total_chemical: totalVol,
total_ac: totalAc,
all_species: allSpecies,
products_used: allProducts
}
});
}
// Use Dictionary() directly — this works in popups and Dashboards
var tableDict = {
fields: [
{ name: "Project_Site", type: "esriFieldTypeString", alias: "Project Site" },
{ name: "total_chemical", type: "esriFieldTypeDouble", alias: "Total Chemical (oz)" },
{ name: "total_ac", type: "esriFieldTypeDouble", alias: "Total Area (ac)" },
{ name: "all_species", type: "esriFieldTypeString", alias: "All Species" },
{ name: "products_used", type: "esriFieldTypeString", alias: "Products Used" }
],
geometryType: "", // no geometry
features: features
};
// Return as FeatureSet
return FeatureSet(tableDict);
Along with this, try to comment from the top down and use console messages, it may show you where exactly it fails.
Cody