Select to view content in your preferred language

SWEET for ArcGIS Arcade Expressions

1101
2
02-21-2022 06:06 PM
Kaz
by
Occasional Contributor

I am using trigger rules in SWEET for ArcGIS to add records to a feature service (logging dataset) whenever there is a change to a primary dataset. I can get this to work if the logging dataset is just a table, but I also want to pass through the original geometry (polygons) of the features that were modified. In the 'Globals' tab in arcade, there seem to be plenty of options to reference the original geometry, however I can't seem to get any of these to work in my script. What am I missing here? Do I need to have separate scripts based on the type of edit? (i.e. one script if new features are added, and another script if features are modified?)

I feel like I'm missing something very simple!

Trigger setup in SWEET: setup in the Data Rules Editor --> selected the layer to watch --> created trigger. 
Trigger event: Post all changes
Data Changes: add records
Layer to apply changes to: hosted feature service (empty polygon dataset)

Arcade Script:

var Edited_Date = Timestamp()
var DCA = FeatureSetByName($modifiedFeatures,"DCA");
var Name = ""
var OID = ""
var geom = geometry(DCA) This is where the script fails. If I set geometry to null and switch the layer to a table, the rest of the script works.
for (var k in DCA){
    var Name = k.Name
    var OID = k.OBJECTID
}
return Feature(geom, { DCA_ID: OID, DCA_NAME: Name, EDIT_TYPE: $operationName, EDITED_BY: $userId, EDIT_DATE: Edited_Date});
Execution Error:Unexpected token o in JSON at position 1

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

The geometry function is expecting a JSON string, or else an individual feature. In your expression, DCA is a FeatureSet. In order to pull out a single feature, you'll need to use something like First to subset a single feature from the set. Alternatively, you can use things like Union to take the set geometries and convert them into a single Geometry object.

Also, do you anticipate this expression running against multiple features? The way this is written, the output will always be the last feature in the for loop.

- Josh Carlson
Kendall County GIS
0 Kudos
Kaz
by
Occasional Contributor

Hi Josh, 

Thanks for the explanation; using first(DCA) now works. However it only works for editing existing polygons (split/reshape). 

I'll need to rethink how I use this expression moving forward as there are different editing scenarios that should be handled separately...for example, I can edit existing polygons using spit/reshape, or create new ones using merge or add, or delete polygons...so using first won't always work. I'll create different expressions depending on the edit type ($operationName). 

0 Kudos