View Full Version : record.commit works but not store.commitChanges

22 Jul 2015, 10:16 AM
Why does the bold line in the code below throw
Uncaught TypeError: Cannot read property 'length' of undefined?If I comment out that line and uncomment record.commit(), it works fine.

url : 'db/Contacts',
method : 'POST',
params : record.getData(),
scope : this,
success: function(response){
record.id = response.id;
var store = this.getDataview().getStore();

Please help.

28 Jul 2015, 7:02 AM
Kind of curious on your workflow here. So you are trying to create a contact and if that is successful then add it to a store? Why couldn't you add it to the store and sync the store so that it manages the success/failure?

29 Jul 2015, 10:14 PM
Thank you, Mitchell.
My server side adds the new record to the DB, generates an id for it and returns the id.
So in my callback, I update the record with the id and then commit the record/store.
Committing the store doesn't work.

30 Jul 2015, 4:49 AM
If you add a record to the store, sync the store then your server returns the data for that record and the store will automatically update the record with that data including the new ID. This should simplify your code to just a store.add(record);store.sync();

30 Jul 2015, 10:49 AM
Thank you, Mitchell.