Rollback or transaction Scope on applyEdits

871
1
11-21-2019 12:14 AM
narendraagrawal
New Contributor II

We are using rest services (NA Services)  to Solve Route and on client side we are using Arcgis javascript api

Now our requirement is that , we have 1 route and we want to store that route and its barrier both for that we have to make 2 database calls using applyEdits method on 2 different layers 1st to store route and  2nd to store barrier 

PROBLEM : Now suppose route is saved successfully but some error occurs while saving on of the  barrier now as they are not saved is there any option to create transaction that either both are saved or both should  rollback. we have seen option in applyEdit rollbackonError but it is valid on single layer only and we have 2 separate layer so how to combine them in single transaction ?   

Can anyone Help ?

1 Reply
MahmoudAdel1
New Contributor

I faced this issue during building an application using ArcGIS JS API 3.x and after making some search I found the solution: 
Read this link first especially the part of example one: 
https://developers.arcgis.com/rest/services-reference/enterprise/apply-edits-feature-service-.htm
You will see you can send request with edits as an array and use id for each layer/table in your map service and each layer/table in edits array can be contains adds, updates or deletes 
Read else the part of rollbackOnFailure, this parameter will handle what you want. 

request(
  urlOfFeatureService + "applyEdits?token=" + token,
  {
    httpMethod: "POST",
    authentication: new UserSession({
      token: token,
    }),
    params: {
      f: "json",
      rollbackOnFailure:true,
      edits:
      // will be like that 
      [
        {
          id:0,     //refer to the layer/table id in the feature server
          deletes:[
            //objectIDs
          ],
          adds:[
            //geometry, attributes in case of layer 
            // attributes in case of table
          ],
          updates:[
            //attributes inclue objectID
          ]
        },
        {
          id:1,     //refer to the layer/table id in the feature server
          deletes:[
            //objectIDs
          ],
          adds:[
            //geometry, attributes in case of layer 
            // attributes in case of table
          ],
          updates:[
            //attributes inclue objectID
          ]
        },
        
        // ..... and so on

      ]
    },
  }
).then((res=> {
 //if all requests success
}).catch(err=>{
  //if one or more requests fail 
  //but the suitable message to user
});