AnsweredAssumed Answered

Arcade Expression throws Data Error / null

Question asked by mcreaney on Jul 31, 2020
Latest reply on Aug 12, 2020 by mcreaney

I'm trying to cross reference work done on a site by the amount of time a vehicle was there.  I have this Arcade script, which tests ok in the script editor but on the map data table shows Data Error and in the popup is null.  Here's the script, can anyone please help to debug?

 

var Asset;
var DateOfVisit;

 

//Get Date of Commission, add to result
var DateOfCommission = Date(year($feature.CreationDate),month($feature.CreationDate),day($feature.CreationDate));
var result = "Date Of Commission = " + DateOfCommission;
Console($feature.CreationDate);
Console(DateOfCommission);

 

var VehicleIntersecting;
var FirstAsset;
var AssetGeometry;
var AssetArea;
var Buffer_Distance = 100;
var AssetID;
var BayID = $feature["bay_guid"];
Console(BayID);
var QueryBay = "GlobalID = '" + BayID + "'";
var QueryAsset;
Console(QueryBay);

 

// Get Associated Bay Record
var Bay = Filter(FeatureSetById($map, /* Production_database - Bay */ "Production_database_3775"), QueryBay);
Console(Bay)

 

// Find GUID of Associated Asset Record
for (var FilteredBay in Bay) {
var AssetID = FilteredBay.asset_guid
Console(AssetID);
var QueryAsset = "GlobalID = '" + AssetID + "'";
Console(QueryAsset);

// Get Associated Asset Record
var Asset = Filter(FeatureSetById($map, /* Production_database */ "Production_database_8049"), QueryAsset);
Console(Asset);
for (var FilteredAsset in Asset) {
var FirstAsset = First(Asset)
var AssetGeometry = Geometry(FirstAsset);
Console(AssetGeometry);

//Buffer 50m around Asset
var Asset_Area = Buffer(FirstAsset, Buffer_Distance, 'meters');
Console(Asset_Area);

//Find Vehicles that intersect Asset ******
var VehicleIntersecting = Intersects(FeatureSetById($map, /* Vehicle Locations */ "Vehicle_Locations_8121"), Asset_Area);
for (var VehicleStop in VehicleIntersecting) {

//Get Date of Visit
var DateOfVisit = Date(year(VehicleStop.date_visited), month(VehicleStop.date_visited), day(VehicleStop.date_visited));
Console (DateOfVisit);
Console (DateOfCommission);
// Add Date of Visit to Result
var result =+ " //// Date Of Visit = " + DateOfVisit;
Console(result);

//Add Visit Duration if Dates of Visit and Commission Match
if (DateOfVisit == DateOfCommission) {
var result =+ " //// Visit Duration = " + VehicleStop.visit_duration;
}
}

}
}
return result;

Outcomes