Select to view content in your preferred language

Arcade Expression throws Data Error / null

3811
21
07-31-2020 07:54 PM
MattCreaney
Occasional Contributor

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 Bugger
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;

Tags (1)
0 Kudos
21 Replies
XanderBakker
Esri Esteemed Contributor

Hi Matt Creaney ,

When I look at the Asset "RG-2-622" I get the result that I was expecting:

Asset OID:1681
Asset name:RG-2-622
DateOfCommission:07/13/2020
# bays count:2

# bay.bay_number:1
## itps count:1
## itp asset_name:RG-2-622
## assets count:1
### asset OID:1681
#### vehicles count:4
##### vehicle:RV2 - Brennen
##### visited:07/20/2020
##### duration:1:47:22
##### vehicle:RV9 - Macca
##### visited:07/20/2020
##### duration:1:26:34
##### vehicle:RV2 - Brennen
##### visited:07/22/2020
##### duration:1:40:36
##### vehicle:RV2 - Brennen
##### visited:07/30/2020
##### duration:0:16:16

# bay.bay_number:2
## itps count:1
## itp asset_name:RG-2-622
## assets count:1
### asset OID:1681
#### vehicles count:4
##### vehicle:RV2 - Brennen
##### visited:07/20/2020
##### duration:1:47:22
##### vehicle:RV9 - Macca
##### visited:07/20/2020
##### duration:1:26:34
##### vehicle:RV2 - Brennen
##### visited:07/22/2020
##### duration:1:40:36
##### vehicle:RV2 - Brennen
##### visited:07/30/2020
##### duration:0:16:16 

What you see here is that the ObjectID of the asset is 1681. When I look for the bays, I get 2 bays as result. But when I go through the related product commission ITP and get the asset, it gets back to asset RG-2-622 with ObjectID 1681. This still confirms my feeling that it would not be necessary to go through the bays and product commission ITP to get to the Asset, since it seems the be the same one the expression started.

Do you have an example where this is not the case?

0 Kudos
MattCreaney
Occasional Contributor

Hi Xander Bakker‌ - No, this is always the case.  The problem is only that I want the script to be executed on the Product Commission ITP layer as this is the task that is related to the vehicle visit. I may even introduce the script result as a new field in the Product Commission ITP table at some stage if I can prove its accuracy as a measure of time spent on site completing the task.  In the short term I wish to be able to display the executed script result in the Product Commission ITP data table and the popup.

0 Kudos