View Full Version : [CLOSED] Validate duplicate record with Auto sync on store.

Jun 02, 2014, 1:38 PM

In ext V2.5, need to prevent duplicate record insertion on store when inserting new record with same existing data. By Using store.sync() method we are inserting/updating/deleting the records from database. A scenario like the store contains ID,Name,Value properties, here ID, Name fields are unique. When inserting same Name into database, checking in the query and returning without record insert, in this case getting message like "Key value is not defined for inserted record".

How to handle this exception?

Thank you.

Jun 02, 2014, 3:51 PM
Hi @iansriley,

To handle that error we can suggest the following.

First of all you should not add a record to e.ResponseRecords if that record fails validation and set some cancel flag which you can access in another page's method (probably, a Page's variable).

if (!validationFailed) {
cancel = true; // You should be able to access

Then you should handle a Store's AfterDirectEvent like that.

protected void Store1_AfterDirectEvent(object sender, AfterDirectEventArgs e)
if (cancel)
e.Response.Success = false;
e.Response.Message = "Error Message";

Also you can set this for the Store to avoid a default failure window

and listen to a Store's Exception client event to show an error as you need:

<Exception Handler="alert(operation.getError());" />

Here is an example. Please try to insert a record and click the "Sync" button.