Saturday 4 April 2020

Interactive grid validation duplicated rows check

APEX and IG validation part 2

 

Interactive grid validation


Check for duplicates using JavaScript


In my first blog I tried to address the problem of checking for duplicated rows in IG but as you have seen it did not cover for most obvious problem which is immediate validation of your data on the client.

If you would to enter two of the same values at one go validation would still submit both to DB which is not what we want. 

Just recently I have seen post by Tobias Arnhold and AskMax on a same subject so......


it only means there is more people challenged with the same problem. 
 
It was on my to do list for a long time and now that everything slowed down I finally found time to see what we can do about it. This example raised so many questions on my previous post so hoping this will help solve some of these too.
 
With snippet of JS added to your page with standard IG based on EMP table with static ID set to 'emp':


Pretty much all of the code is taken from John Snyder's IG cookbook examples and I added a section to check for duplicates. 
  
Download the full JS.  

That should be all. 
Leaving you with live demo @here.


Happy APEXing,
Lino

29 comments:

  1. how to use this JS code?
    Thanks

    ReplyDelete
    Replies
    1. Copy and paste it into your Function and Global Variable Declaration section of the page

      Delete
    2. it's working. thanks.
      i want auto serial no in a IG column for save. not Sequence Row Header. is it possible.

      Delete
    3. Yes it is possible, check how we are getting Salary and Empno on JS lines 11 and 12

      Delete
    4. i would like to check duplicate in a single column.. is it possible to check ?

      Delete
  2. Can you please explain what is salary in line 28
    Also hitting with the below error, how to fix
    Error: Line 28:['salary'] is better written in dot notation.

    ReplyDelete
  3. Please ignore my previous post.
    I was able to resolve the same

    ReplyDelete
  4. It works fine in apex 19.1, thank you very much. I'll see the way to solve that problem in apex 5.1

    ReplyDelete
  5. Will it work with filters

    ReplyDelete
    Replies
    1. I tried disabling the filters before the model is fetched but as disabling filter is asynchronous it dint help

      Delete
    2. I didn't try this with filters yet. It may have to do with a 'filtered' view and data collected by IG where it seems my current solution looks at whole loaded model.

      Delete
  6. hey so i added this in Function and Global Variable Declaration but its not working....added a table with columns id, emp, sal ...any idea why?

    ReplyDelete
    Replies
    1. Please make sure you copy the code into Function and Global Variable Declaration and that you give your IG region a static ID emp

      Delete
  7. Where should I call this function? SHould I create a DA on the Emp Name and call update(model)?

    ReplyDelete
    Replies
    1. Please make sure you copy the code into Function and Global Variable Declaration and that you give your IG region a static ID emp

      Delete
  8. its looking good but i don't know where to write this code and how to call it. any one can please guide me.

    ReplyDelete
    Replies
    1. Copy and paste it into your Function and Global Variable Declaration section of the page

      Delete
  9. Hello,
    i tried to check duplicate records on ENAME columns but no luck.
    could you please let me know how to check duplicate ENAME in the same JS.

    Thanks

    ReplyDelete
    Replies
    1. It should be easy.... similar to before https://apex.oracle.com/pls/apex/f?p=84111:22 does the ename checks. This is the JS used here https://jsfiddle.net/xn50cr6a/

      Delete
    2. Hi, Even we have the requirement to check duplicate for the Varchar ( Ename ) example, is there a chance to share that JS code

      Delete
    3. https://jsfiddle.net/xn50cr6a/

      Delete
    4. Hi, Even we have the requirement to check duplicate for the Varchar ( Ename and Sal ) if two or more then cloumn value same then duplicate message

      Delete
    5. var duplicateIds = recArray
      .map(e => e['empname'])
      .map((e, i, final) => final.indexOf(e) !== i && i)
      .filter(obj => recArray[obj])
      .map(e => recArray[e]["empname"]);
      this code if (empname And Sal ) Same Value Then duplicateIds >0 How can i Do this

      Delete
  10. This comment has been removed by the author.

    ReplyDelete
  11. Hi I have two column i.e STORY_WORK_ORDER_ID(primary_key) and WORK_ORDER_ID and i want to validate that user cannot add two same work_order

    ReplyDelete
    Replies
    1. thankyou i found the issue work now perfect solution.

      Delete