Hello! I am working on a Field Maps project where users in the field are inspecting parking lots. I am using 11.1 Enterprise Portal.
I created a layer of the parking lots that need to be inspected and I created a related table for the inspections. I then created a web map with the layer and now I am setting up the Field Maps form.
Everything is working as intended however I want to calculate a couple answers from the Parking Lots layer into the Inspection Form to ensure data accuracy like the Lot Name and the Lot ID.
I had this working on my AGOL prototype with the following code:
var LotData = FeatureSetByRelationshipName($feature, "ParkingLots", ['*'], false);
var Pull = First(LotData)
if(Pull == null) {
Console("Data is null -> Data is empty")
} else {
Console(Pull.Lot_Name)
}
return(Pull.Lot_Name)
I rewrote it to switch to Enterprise. It "works" however it always returns the attributes of Lot #1. FeatureSetByRelationShipName was not working so I switched to FeatureSetByName. New code below:
var LotData= FeatureSetByName($datastore,"ParkingLots", ['*'], false)
var record = First(LotData)
if (IsEmpty(record)){
return "No Record Found"
}
return record['lot_name']
Any ideas?
I have a feeling I need to use Filter before First however I have not been able to get anything to work.
Thanks!
Solved! Go to Solution.
Alright I think I figured it out. I'll try to include as information much as possible so if anyone else finds this thread.
Definitely multiple issues were encountered but this is the resulting code that works:
if(IsEmpty($feature.guid)) {
return "null"
}
else {
var results = First(FeatureSetByRelationshipName($feature, "ParkingLots", ['*'], false))
return results.lot_name
}
Lines 1 and 2 solve the Filter issue - see why in the answer of this Post
I split the previous attempt's last line into Lines 5 & 6 because it was returning all of the fields as well as the geometry. Now Line 5 pulls the data but Line 6 returns only the desired field.
Yes, you'll need the Filter function to get the proper record. Use the proper field names for the common fields linking the table to the FeatureSet in lines 1 and 3.
var asset = $feature.thecommonfield
var LotData= FeatureSetByName($datastore,"ParkingLots", ['*'], false)
var record = First(Filter(LotData, "thecommonfield = @asset)
if (IsEmpty(record)) return "No Record Found"
return record['lot_name']
Hi @KenBuja ! Thank you for the response.
I found your response for another similar issue: https://community.esri.com/t5/arcgis-online-questions/arcade-script-for-layer-to-layer-calculation/m... however the code is still not working.
var asset_id = $feature.guid
var LotData = FeatureSetByRelationshipName($feature, 'ParkingLots', ['*'], false)
var results = First(Filter(LotData, "GlobalID = @asset_id"))
if(IsEmpty(results)){
return "No Record Found"
} else {
return results['lot_name']
}
First, the results are "a is null" or sometimes I get "d is null" and the console breaks at line 3. If I replace $feature with $datastore and remove the Filter it will just pull the data from the first parking lot.
var asset_id = $feature.guid
var LotData = FeatureSetByName($datastore,"ParkingLots", ['*'], false)
var results = First(LotData)
if(IsEmpty(results)){
return "No Record Found"
} else {
return results['lot_name']
}
Second, if I add the Filter function back in it goes back to "a is null". I am wondering if the Filter's Boolean is wrong? Or is this simply a connection issue related to $feature?
Any thoughts? Thanks in advance!
I also tried using FeatureSetByPortalItem instead and that is when I get "d is null"
Update: I found another related post: https://community.esri.com/t5/developers-questions/arcade-error-when-accessing-empty-feature-set/td-...
if(IsEmpty($feature.guid)) {
return "null"
}
else {
return First(FeatureSetByRelationshipName($feature, "ParkandRideLots", ['lot_name'], false))
}
It is now returning the correct feature however it returns the entire feature starting with geometry. There seems to be an issue with the FeatureSetByRelationshipName function as it ignores the optional fieldname and includeGeometry.
Any ideas??
Alright I think I figured it out. I'll try to include as information much as possible so if anyone else finds this thread.
Definitely multiple issues were encountered but this is the resulting code that works:
if(IsEmpty($feature.guid)) {
return "null"
}
else {
var results = First(FeatureSetByRelationshipName($feature, "ParkingLots", ['*'], false))
return results.lot_name
}
Lines 1 and 2 solve the Filter issue - see why in the answer of this Post
I split the previous attempt's last line into Lines 5 & 6 because it was returning all of the fields as well as the geometry. Now Line 5 pulls the data but Line 6 returns only the desired field.