The add, delete, modify records task will change one or more features to a target layer.

The user must specify the target layer. The layer can be a layer in the web map or an externally referenced layer.

The add, delete, modify task must return a dictionary of records to delete, records to insert and records to add. This dictionary should be in the form

{
  insert: <list of features to insert>,
  update: <features to update>
  delete: <features to delete>.
  //, crackandcluster: true // Optional to cause cracking
  // and clustering to occur as a final stage to the operator
}

The properties of the return dictionary support many different forms:

insert

This should be an array of feature items.

delete

This can be a FeatureSet derived (as a filter or spatial filter) from $targetLayer. Alternatively it can be an array of features (initially derived from $targetlayer, or a list of object ids).

modify

This can be a FeatureSet derived from the ChangeShapeAndAttributes, or more easily an array of change items. A change item references a feature or an object id and provides a set of attributes to change and/or an updated geometry.

The examples below illustrate how to use the return dictionary.

Example data scripts

Add, modify, delete using object ids and arrays

var deletefeat = first(FeatureSetByName($map, "Layer E")); // Get a feature to delete
var thisfeat = first(filter(FeatureSetByName($map, "Layer E"), "ID=222")); // Get a feature to modify

return {
  delete: [
    deletefeat, //Feature
    122, //ObjectID
    2828 //ObjectID
  ],
  insert: [
    Feature(
      Point({ x: 1000, y: 1000, spatialReference: { wkid: 102100 } }),
    { attr1: "some attribute", attr2: "another attribute" })
  ],
  update: [
    {
      objectId: 111, // Use ObjectID or a feature
      attributes: {
        // Any set of attributes of change
        changeme: 10
      }
    },
    {
      //Feature
      feature: thisfeat,

      //Only the attributes listed in the new feature will be replaced,
      //the other attributes of the original feature will be preserved.
      attributes: {
        changeme: 10
      },
      // Change the geometry as well
      geometry: buffer(thisfeat, 10)
    }
  ]
};

Failing the whole operation

return {
  error: "Cannot add as items already exist"
};