This script runs successfully when I test in the webmap against the service- see the attached image.
However, I get an error once I try to use in attribute rules using ArcPro 2.7.x. I'm new to attribute rules, and will appreciate any help folks on this forum.
I have a liftstation featureclass with a related table for repeat inspections using collector. I need a rule that will populated the station name from the liftstation featureclass to a field in the related table.
I get the error "Invalid expression Error on line 6 General evaluation error" . It's failing at the line "{
output += related_row.STATIONNAME"}
Here's the code used in attribute rules.
//get the guid of the table feature being updated
var filter_query = "GlobalID = '" + $feature.LStationID +"'"
//find the lift station layer
//$datastore is the current geodatabase
//get the GlobalId and STATIONNAME field
var related_fs = FeatureSetByName($datastore, 'gisdmz.SDECB.wwLiftStation',['GlobalID','STATIONNAME'])
//get the guid of the table feature being updated
var filter_query = "GlobalID = '" + $feature.LStationID +"'"
//find the station by filtering on the Guid
var related_filter = Filter(related_fs, filter_query)
var output = ''
for (var related_row in related_filter){
output += related_row.STATIONNAME
}
return {
"result": output
}
Solved! Go to Solution.
Hard to tell from the script whats going on, but I modified the script to be more readable and less error prune by using the inline sql semantics so it takes care things for us like adding single quotes or dates predicates
You get the error on that line because thats when Arcade actually executes the query filter, make sure that the stationId is actually a valid globalId.
//get the guid of the table feature being updated
var lstationId = $feature.LStationID;
var filter_query = "GlobalID = @lstationId";
//find the lift station layer
//$datastore is the current geodatabase
//get the GlobalId and STATIONNAME field
var related_fs = FeatureSetByName($datastore, 'gisdmz.SDECB.wwLiftStation',['GlobalID','STATIONNAME'])
//get the guid of the table feature being updated
var filter_query = "GlobalID = @lstationId";
//find the station by filtering on the Guid
var related_filter = Filter(related_fs, filter_query)
var output = ''
for (var related_row in related_filter)
output += related_row.STATIONNAME
return {
"result": output
}
Hard to tell from the script whats going on, but I modified the script to be more readable and less error prune by using the inline sql semantics so it takes care things for us like adding single quotes or dates predicates
You get the error on that line because thats when Arcade actually executes the query filter, make sure that the stationId is actually a valid globalId.
//get the guid of the table feature being updated
var lstationId = $feature.LStationID;
var filter_query = "GlobalID = @lstationId";
//find the lift station layer
//$datastore is the current geodatabase
//get the GlobalId and STATIONNAME field
var related_fs = FeatureSetByName($datastore, 'gisdmz.SDECB.wwLiftStation',['GlobalID','STATIONNAME'])
//get the guid of the table feature being updated
var filter_query = "GlobalID = @lstationId";
//find the station by filtering on the Guid
var related_filter = Filter(related_fs, filter_query)
var output = ''
for (var related_row in related_filter)
output += related_row.STATIONNAME
return {
"result": output
}
Thank you. Now it validates in ArcGIS Pro- I also added a line to check for a valid value before populating the record. Now I will test that it works in the Collector app.