Select to view content in your preferred language

Arcade script failed in Field Maps but works in ArcGIS Online

407
0
10-27-2023 09:00 AM
Labels (2)
SMauri
by
Frequent Contributor

Hi all,

I've been trying to use Arcade to run some calculations in forms on ArcGIS Online.

In a nutshell, I have to read the values ​​of the upstream and downstream node of the line that I generate on the map.

Here is my code, appropriately modified starting from this one hosted on esri-github repository: arcade-expressions/attribute_rule_calculation/CopyValueIntersectingFeature.md at master · Esri/arcad...

Upstream node

 

 

// Value to copy from the intersected feature
var intersecting_field = "IDCAMERE";

var paths = Geometry($feature)['paths'];

var FirstVertex = Point(paths[0][0])

// Create feature set to the intersecting class using the GDB Name
var intersecting_featset = FeatureSetById($map, "18697a2e245-layer-2", [intersecting_field])

// Intersect the edited feature with the feature set and retrieve the first feature
// var intersected_feature = First(Intersects(intersecting_featset, $feature));
var intersected_feature = First(Intersects(intersecting_featset, Buffer(FirstVertex,1)));

// Check to make sure there was an intersected feature, if not, return the original value
if (IsEmpty(intersected_feature) || intersected_feature == null)
{ 
    return -99;
}
// If the intersected feature is null, return the original value
if (IsEmpty(intersected_feature[intersecting_field]))
{
    return -99;
}
return intersected_feature[intersecting_field]

 

 

 

Downstream node

 

 

// This rule will populate the edited features field with a value from an intersecting feature

// Value to copy from the intersected feature
var intersecting_field = "IDCAMERE";

var paths = Geometry($feature)['paths'];

var LastVertex = Point(paths[-1][-1])

// Create feature set to the intersecting class using the GDB Name
var intersecting_featset = FeatureSetById($map, "18697a2e245-layer-2", [intersecting_field])

// Intersect the edited feature with the feature set and retrieve the first feature
// var intersected_feature = First(Intersects(intersecting_featset, $feature));
var intersected_feature = First(Intersects(intersecting_featset, Buffer(LastVertex,1)));

// Check to make sure there was an intersected feature, if not, return the original value
if (IsEmpty(intersected_feature) || intersected_feature == null)
{ 
    return -99;
}
// If the intersected feature is null, return the original value
if (IsEmpty(intersected_feature[intersecting_field]))
{
    return -99;
}
return intersected_feature[intersecting_field]

 

 

 

But when I create a new line in Field Maps on a mobile device, script returns the first value of table "nodi" (my points) instead of  intersected vertex with "current" geometry (my new line).

SMauri_0-1698421727671.png

And so what I get is a double insertion of the first value in the table. But when I open the same map in ArcGIS Online and edit this new line, the script works according to the expected behavior.

Where am I doing wrong? Any ideas? 

Stefano

 

0 Replies