Select to view content in your preferred language

applyEdits in squence - FeatureService vs. Layer - AttributeRule at TransactionEnd

98
1
yesterday
SebastianKrings
Frequent Contributor

Hi,

Problem
currently we are using the applyEdits function of the featureLayer.
Unfortunately we now face the following problem:

  • There is an object which may consists of multiple addresses.
  • only one address can be the main-address
  • main-address can be switched to another non-main-address
  • there is an attribute rule checking that there is at most one main-address

When this is sent via applyEdits the execution order seems random or maybe by uid.
This leads to the not-yet-main-address to be given the main-address attribute first before the main-address attribute is revoked from the original mainAddress.

Means there are two main-addresses at once violating the attribute rule and thus aborting the transaction.

ApplyEdits: FeatureService vs. FeatureLayer
We are using

featureLayer.applyEdits()

There are two different applyEdits APIs:

Unfortunately they behave different.
The FeatureService offers this param:

FeatureServiceApplyEditsOptions.honorSequenceOfEdits

Which is not available for:

FeatureLayerApplyEditsOptions

 

Additionally their edits JSON are built differently as far as I understood documentation.

Searching for Solution

Workaround 1 (not suitable)
I would not like to split this into two different transactions. In case one excepts the other cannot be invalidated any more.

Question1
Is there any way to allow sequence order for featureLayer.applyEdits too?

Question2
How do I use FeatureService applyEdits in Arc JS? The FeatureLayer to perform for + applyEdits JSON from FeatureLayer.applyEdits is given
Examples I found so far only describe the FeatureLayer applyEdits.

I found this sample:
https://developers.arcgis.com/arcgis-rest-js/api-reference/arcgis-rest-feature-service/applyEdits/

import { applyEdits } from '@esri/arcgis-rest-feature-service';
//
applyEdits({
 url: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/ServiceRequest/FeatureServer/0",
 adds: [{
   geometry: { x: -120, y: 45, spatialReference: { wkid: 4326 } },
   attributes: { status: "alive" }
 }],
 updates: [{
   attributes: { OBJECTID: 1004, status: "alive" }
 }],
 deletes: [862, 1548]
})
 .then(response)

 

Question3

Is there may another way for the AttributeRule to be postponed to the end of the transaction after all edits were done in place but right before the changes will be persisted.

But the stated import does not work, erros are given, that it cannot be found.
I am using arcgisCore 4.34

0 Kudos
1 Reply
LeoMontero
Emerging Contributor

Question2
How do I use FeatureService applyEdits in Arc JS? The FeatureLayer to perform for + applyEdits JSON from FeatureLayer.applyEdits is given
Examples I found so far only describe the FeatureLayer applyEdits.

@SebastianKrings 

Please read below for a code snippet showing how to leverage FeatureService.applyEdits.

BTW, FeatureService.applyEdits doc does include a code snippet (It only shows how to add features to a single layer though).

import Graphic from "esri/Graphic";
import FeatureService from "esri/rest/featureService/FeatureService";

const featureServerUrl = "https://myServer/server/rest/services/myService/FeatureServer";

const featureService = new FeatureService({
  url: featureServerUrl,
});

const pointGraphic = new Graphic({
  geometry: {
    type: "point",
    spatialReference: { wkid: 4326 },
    longitude: 0,
    latitude: 3,
  },
  // attributes: {},
});

const lineGraphic = new Graphic({
  geometry: {
    type: "polyline",
    spatialReference: { wkid: 4326 },
    paths: [
      [
        [0, 3],
        [2, 5],
      ],
    ],
  },
  // attributes: {},
});

const edits = [
  {
    id: 1,
    addFeatures: [lineGraphic],
    // updateFeatures: [],
    // deleteFeatures: []
  },
  {
    id: 0,
    addFeatures: [pointGraphic],
    // updateFeatures: [],
    // deleteFeatures: []
  },
];

const serviceEditsOptions = {
  // gdbVersion: "OWNER.VersionName",
  honorSequenceOfEdits: true,
};

if (!featureService.loaded) {
  await featureService.load();
}

featureService.applyEdits(edits, serviceEditsOptions).then((result) => {
  console.log("featureService.applyEdits - result", result);
});