How to use ApplyEdits for two  FeatureLayers

4697
19
06-26-2014 07:12 AM
EdibertoAlves1
New Contributor
Hi,
I have two FeatureLayers in my FeatureServer service, and I would like to know how to insert data inside fields these using applyEdits method.
Please, anybody help?

Thanks
0 Kudos
19 Replies
EdibertoAlves1
New Contributor
someone help me?
0 Kudos
saurabhgupta2
New Contributor II

Hi

I also want to do the same..Have u got any answer for ur question?

Regards

Saurabh

0 Kudos
Vara_PrasadM_S
Occasional Contributor II

Hi Ediberto Alves & Saurabh Gupta,

You can follow the below procedure.

1. Create objects for both the featurelayers of your Feature server service using "FeatureLayer" class as shown in below example.

var landuseLineLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Military/FeatureServer/8", {
          mode
: FeatureLayer.MODE_SNAPSHOT,
          outFields
: ["*"]
       
});

2. Now create Graphic objects to be inserted into the feature Layers, add call "applyEdits" by passing the array of the Graphic objects as first parameter.

3. To Update any features, pass the array objects of the features interms of objects of Graphics as second parameter to "applyEdits" function.

4. To Delete, pass the array of graphic objects as third parameter to "applyEdits" function.

Example:

<featureLayerObj>.applyEdits(addGraphicsArr, updateGraphicsArr , deleteGraphicsArr);

Please let me know if you are looking for something else or you need any more details.

Thanks & Regards,

Vara Prasad.

0 Kudos
saurabhgupta2
New Contributor II

Hi Vara

Thanks for the reply . But I am trying to update some attribute of my feature service or add new feature to it. I can do it through service page (HTML). I am just trying to do it from my .net code (attached below). As i can see that HTML post option works fine without any Arcgis LIB. Can I do it the way I am approaching or something on these line?

https://community.esri.com/message/311103?sr=search&searchId=895cbc49-833f-4835-b6c6-6699f303bbcb&se...

I am not much of exp in java script API so your guidance will be very valuable

Regards and Thanks

Saurabh

0 Kudos
Vara_PrasadM_S
Occasional Contributor II

Hi Saurabh,

Yes, definitely you can do this through a simple POST request approach. We can do both attribute updates, geometry updates, new feature creation, deletion by sending a POST request, just similar to calling "applyEdits" function.

I have gone through your post in the mentioned link.

It is required to use Proxy page for editing. Have you used any proxy page configured in your application. If not, please go through the below link

https://developers.arcgis.com/javascript/jshelp/ags_proxy.html

Please send me the error that you are facing, It helps me in identifying the issue.

Thanks & Regards,

Vara Prasad.

0 Kudos
saurabhgupta2
New Contributor II

Hi Vara

Thanks for your prompt reply. I have not set proxy page on my server. Secondly as far as my code goes ( from txt) i got this error

success: {"error":{"code":500,"message":"Unable to complete operation.","details":["No edits ('adds', 'updates' or 'deletes') were specified."]}}

Regards and Thanks

Saurabh

0 Kudos
Vara_PrasadM_S
Occasional Contributor II

Hi Saurabh,

I did not check your code earlier. Now I have verified it and found that the request string is not in correct syntax, expected by "applyEdits" of "Feature Service".

Please go through the below url (ArcGIS Server REST API).

http://resources.arcgis.com/en/help/rest/apiref/fsserviceedits.html

In the above link, there is example/sample.

After going through your old posts, i found that you are using the syntax which you have used for "UpdateFeatures" request. However, the syntax for "ApplyEdits" is completely different.

Thanks & Regards,

Vara Prasad.

0 Kudos
saurabhgupta2
New Contributor II

Hi Vara

I am not able to get where im making mistake. I have posted new code as per the link but its throws an error of NAN

  var strURI =  "http://servicesbeta2.esri.com/arcgis/rest/services/PoolPermits/FeatureServer/applyEdits"

      

        var objdata = [

    {

        "id" : 0,

    

        "deletes" : [

            19,23

        ]

    },

    {

        "id" : 1,

        "deletes" : [

            34,44

        ]

    }

        ] ;

    

        $.ajax({

          

            corsDetection: true,

            crossDomain: true,

           beforeSend: function (request) { request.setRequestHeader("Access-Control-Request-Headers", "*") },

            type: "POST", //GET or POST or PUT or DELETE verb

            url: strURI,

            data: objdata, //Data sent to server

            //contentType: "application/json; charset=utf-8", // content type sent to server

            dataType: "json", //Expected data format from server

            async: false,

            processdata: true, //True or False

            success: function (data) { alert("success: " + JSON.stringify(data)); },

            error: function (data) { alert("error "+ + JSON.stringify(data)); },

            statusCode: {

                200: function () { alert("200 OK"); },

                304: function () { alert("304 Not Modified"); },

                404: function () { alert("404 No Found"); }

            },

            isModified: function () { alert("Something was modified"); }

        });

I have used code for update features but then i come across that i can use ApplyEdits also as my server is 10.2

So i changed it to applyedits . How ever i was not able to do the same process through UpdateFeature

Please help me to find where im doing it wrong

Thanks and regards

Saurabh

0 Kudos
Vara_PrasadM_S
Occasional Contributor II

Saurabh,

Could you please try with below json array as input value and make sure to update the numbers (ObjectIds) mentioned for deletes to represent features of layers with ids 0 and 1.

[

    {

         "id" : 0,

        "adds" : [           

        ],

         "updates" : [

        ],

        "deletes" : [

            19,23

        ]

    },

    {

        "id" : 1,

  "adds" : [           

        ],

         "updates" : [

        ],

        "deletes" : [

            34,44

        ]

    }

]

Thanks & Regards,

Vara Prasad.

0 Kudos