Skip to Content

best way to check if a row already exists in ui5 before insertion

Sep 05, 2017 at 08:52 AM


avatar image
Former Member

Hi Guys,

what will be the best way to check if the row is already exists in UI5 table before insetion a new record in ui5 table.

I thought i will check the record which i'm going to insert by doing oModel.Read and if the record exists then give message to user if not insert a new record.

Can you share your views or the methods?


10 |10000 characters needed characters left characters exceeded

You can indeed perform a read operation to the backend by passing as a parameter the key field of the record to the read function and if you get the record in the response conclude the record already exists. Else call the create function to create the record in the backend.

Former Member
saurabh vakil

right.. the same way i was thinking. i would welcome if i get any other methods to do the same.

* Please Login or Register to Answer, Follow or Comment.

3 Answers

Sharath M G Sep 06, 2017 at 07:10 AM

For the data in a view control ex: table, we can either check for the data through the control id or through the model bound to the control.

I would suggest, checking with the model data, as based on the entries of the model the rows are created in the control.

If the model is empty, then there are no rows in the table.



Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

We have the data in the model , we just want to verify before inserting a new record the same shouldn't exists already otherwise it will create junk data. If the newly created record is already present we can give information to the user that this row already exists.


Is there any data variable(in the row) which is unique? If yes, then get the existing data/row in the table.

Loop through it by checking for any duplicate value of the Key variable in that model. Is duplicate exists, then do not create a row.

Joseph BERTHE Sep 07, 2017 at 11:17 AM


You can check with the key of your entry. If your table is bound to OData model, then you can check if the entry exist with that code :

var entry = myOdataModel.getProperty("/myService(key1='value1',key2='value2')");

The entry variable will tell you if there is something or not.


Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Can the value1 and value2 be taken runtime? i mean i want to pass the same values which i will get from the textfield entered by user.


Yes of course, you can use it dynamically.

You can do something like :

var myUniqueKEy = myOdataModel.createKey("/myService", {
  key1: myVar1,
  key2: myVar2
var entry = myOdataModel.getProperyty(myUniqueKEy);

Sachin Dhavanam Sep 11, 2017 at 01:29 PM

Hi Anurag,

My suggestion is to use model to check the duplicate which is associate with the table.

We have function in javascript.

oTableModel = this.getModel("TableModel");
var iIndex = {

It will return true, if that model already contains same id.

Using this you can avoid duplicated in your table.

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

thanks.. i will apply this solution and let you know.