PDA

View Full Version : Store how to get last insert id ?



mhmda
19 Nov 2014, 5:42 AM
I use rest proxy, I want to know the last 'id' of last insert record, my server side respond as it should be:

before saving:

id:-1

Save:

var values = this.getFrmReciept().getValues();
var record = this.getFrmReciept().getRecord();
var store = Ext.getStore('recStore');
record.set(values);
record.save();
store.add(record);
alert(record.data.id);//result is '-1'


Respond from server:


{"success":true,"reciept":[{"id":"366","c_id":"57","crdt_auth":"test","typ":"2","clerk_id":"1"}]}

After saving I use the same record to get the new 'id':


alert(record.data.id);//result is '-1'


How can I get the new 'id' that returned from the server?

Thank you in advice

mhmda
19 Nov 2014, 8:52 AM
I found answer in stackoverflow after I post question there and here the solution:


var newId = -1;

record.save({ success: function (rec, op) {
newId = rec.getId(); alert(newId);
}
});