Arcade Calculate Rule, update Shape field not working with api applyEdits

2137
10
10-20-2020 10:40 PM
calebmelies1
New Contributor

I used the example rule from this ESRI example to update the Shape field of features on insert. The rule works great when adding/updating features via Pro or Portal maps but not from applyEdits API call made to the ArcGIS Enterprise Feature Service end point.  Is this a bug?

ArcGIS Pro: 2.6
ArcGIS Enterprise 10.8.1

SQL Server

ArcGIS Server Log Error:

0 Kudos
10 Replies
XanderBakker
Esri Esteemed Contributor

Hi caleb melies ,

I would expect that when editing a service in Pro or in a Portal web map, you will still be using REST to make the edits. Can you share a screenshot or text of how you have structured your applyEdits?

How you monitored the network traffic when editing a web map to see how the REST call is structured?

No sure if there might be any restrictions on update a Shape field...

0 Kudos
calebmelies1
New Contributor

Hi Xander Bakker‌,

I thought the same thing about Pro/Portal/API all using REST to make edits. I've included a screenshot from Postman below. I've also tested other attribute rules on non-geometry fields and those update as expected using this method.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi caleb melies , 

The screenshot is from the error when using the REST API as far a I understand. The json for the feature seems to be ok (at least I don't see what could be wrong with it). 

Can you capture an edit done in the web map over the same feature with the same attribute rule? My suggestion would be to compare those and see if the request is somehow formatted differently. I will also tag the Attribute Rules place.

CC Attribute Rules

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

Can you post your script? The adds call does not look correct.

0 Kudos
calebmelies1
New Contributor

I just noticed I am in fact getting the error when editing the feature service in Pro.

Here is a screenshot of the script (also in text below). I tried to keep it as close to the ESRI example I referenced:

//This calculation attribute rule is added to the shape field of a point feature class called pointClass2
var centerFeature = First(FeatureSetByName($datastore, "density.DBO.zipCodes"))
//Get the x and y values of the feature in the pointClass1
var x0 = Geometry(centerFeature).x
var y0 = Geometry(centerFeature).y
//Get the x and y values of the current feature in the pointClass2
var x1 = Geometry($feature).x;
var y1 = Geometry($feature).y;
var x2 = 0;
var y2 = 0;
var d = 5
//Calculate the euclidean distance from feature in pointClass1 and current feature in pointClass2
var d1 = sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0))

//Calculate the new x and y to be within 5 metric units while maintaining slope
x2 = (x1 - x0) * d / d1 + x0;
y2 = (y1 - y0) * d / d1 + y0;
//Create a point geometry from the new x and y values
var pointA = Point({
"x": x2,
"y": y2,
"z": 0,
"spatialReference": Geometry(centerFeature).spatialReference
});
return pointA

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

I would suggest moving this to a pop up and add return statements along the way to see where it is breaking.

I would start by looking at the geometry (centerfeature).x line. Are zip codes polygons? If so, not sure what .x or .y would even return.

calebmelies1
New Contributor

Michael Miller Config Pop-ups with scripts is great advice for saving time (I encourage my team to do this when possible)!  For this application, we are storing zip code center points.  I have tested the script in the pop-up and it works as expected.  

0 Kudos
calebmelies1
New Contributor

One more note... This does work when adding a feature on a map connected directly to the DB but not when adding a feature on a map connected to the Feature Service.  And Config Popups on the Feature Service map can't find the zipCode layer via $datastore?  This works in the map connected to the database.

0 Kudos
MikeMillerGIS
Esri Frequent Contributor

Is the zip code layer in the feature service? If not, will not work in a pop up as the data store is the feature service for the client and pop ups execute client side

0 Kudos