Select to view content in your preferred language

applyEdit function for Delete

5920
11
10-21-2015 10:50 AM
AnggaHidayah_Ramadhan
Deactivated User

I have problem with my javascript code for Apply.edit here the code

delMaintData:  function(){

    console.log('Bri');

                var maintTable = new FeatureLayer(this.dataSelect.get("value"));

                console.log('layer',maintTable);

                var delrecord = this.OBJECTID.get('value');

                console.log(delrecord);

                maintTable.applyEdits( null, null, delrecord, function(delrecord){

                    //readTable(dijit.byId('assetId').get('value'));

                    //dijit.byId('dialogAsset').hide();

                    console.log(delrecord);

                });

        }

Until this code console.log(delrecord); , the code still working properly that will produce the object id to delete

But  on console.log(delrecord); will produce Undefined that means unable to complete operation. Anything problem or are there anything mistakes ?

Please help me. Thanks

0 Kudos
11 Replies
KenBuja
MVP Esteemed Contributor

applyEdits is expecting an array of items for the first three parameters, but you're supplying a single item. For example, this would update the targetGraphic in this featureLayer

featureLayer.applyEdits(null, [targetGraphic], null);

0 Kudos
AnggaHidayah_Ramadhan
Deactivated User

i have been make the  delrecord in Array. But now i have error

Uncaught TypeError: Cannot read property 'undefined' of undefined

that means my code fail on the 

maintTable.applyEdits( null, null, [delrecord], function(delrecord)

different if i not use array that error just on the

  console.log(delrecord);

How about it ?

0 Kudos
KenBuja
MVP Esteemed Contributor

What is the object delrecord? I can't quite follow what it represents when you first assign it a value.

0 Kudos
AnggaHidayah_Ramadhan
Deactivated User

delrecord is ObjectID.

var delrecord = this.OBJECTID.get('value');

                console.log(delrecord);  <-- this log will be represent the Object. Id that i have get it. and i put in the

Apply.Edits(null,null,[delrecord]) to make the function of the applyedit Delete.

0 Kudos
KenBuja
MVP Esteemed Contributor

I haven't worked with tables when using applyEdits, so I don't know if you can just supply an ObjectID. The documentation shows that is it is expecting an array of Graphics...much different than just an ObjectID.

KarenRobine
Frequent Contributor

I think Angga is correct. The applyEdits for deletes on related tables seems to not work the expected way. I believe there might be a bug in ESRI's way of handling deletes on related tables. From the rest service, it is expecting a comma-delimited set of Object Ids..


I worked around this using an esriRequest with a post, and was able to make it work that way.  FYI: I am using the ESRI JS API Version 3.18.

0 Kudos
thejuskambi
Frequent Contributor

The apply edits for FeatureLayer in JS api is different then the REST api. As Ken suggest, the FeatureLayer.applyEdits is expecting an array of Graphics (which contains valid objectids) and not just object id as integer array.

There is no restricting in using the esriRequest to access the REST api directly, however, if your are using the JS api, you are required to provide valid parameters as mentioned in the api documentation.

0 Kudos
KarenRobine
Frequent Contributor

Thejus:
Are you saying that the applyEdits is actually working for related tables?  Since the related table isn't graphics or features, I don't see how you can truly create a graphic for a related table (setup with relationship classes), unless its a related feature.

I used the Rest API and just sent a string of Object Ids for the related table.

0 Kudos
thejuskambi
Frequent Contributor

I have not worked much with related tables, but if you are creating a FeatureLayer for a stand-alone table and try to applyedit it should work, similar to your esriRequest. If you note, in the request for "editing related tables", you are sending a layer id for the related table and not for the FeatureLayer. A FeatureLayer can be spatial or non-spatial, so if create an instance of FeatureLayer for your related table, you should be able to apply edits, similar to other feature layers.

Regarding creating graphic objects, you could use the queryRelatedFeatures() or simply create a new graphic object with no geometry and add the attributes(with object id).

If you could setup as Jsbin, I could take a look at the issues you are facing.