Skip to Content
avatar image
Former Member

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

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?


Add comment
10|10000 characters needed 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.

  • Get RSS Feed

3 Answers

  • 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.



    Add comment
    10|10000 characters needed characters exceeded

    • 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.

  • 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.


    Add comment
    10|10000 characters needed characters exceeded

    • 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);

  • 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.

    Add comment
    10|10000 characters needed characters exceeded