Presave check for duplicate in list before saving

Home Forums Classic DFFS Presave check for duplicate in list before saving

Viewing 2 reply threads
  • Author
    Posts
    • #35866
      Travis Goodman
      Participant

        Hi Alexander,

        Long time, no talk! Got a question for you. I have a VERY large list that keeps weekly hours of operations for hundreds of locations. I want to come up with a way to prevent a duplicate from being created by doing a check of more than one column value. Let’s just say Column A, Column B, and Column C. Column A is a text column, Column B is a date column, and Column C is a lookup column.

        I want to make sure no one tries to submit a record that already exists where all three of these columns match the item they are trying to create. Is there anything for that or any trick you may know of?

      • #35867
        Keith Hudson
        Participant

          Travis, this might work: If you populate the title field by a rule that concatenates the three fields you are referring to, and set the title field (on the native sharepoint list settings) to NOT allow duplicates in the title field, SharePoint will prevent any duplicates.

          You could enhance the user experience by explaining on the form that the combination of the three fields needs to be unique, so they have some idea why SharePoint is giving them a very obtuse error message.

          You could use vLookup (must be set up carefully on a new form, but very do-able) to show any other items from the list that have the same title as they choose those three fields. You could even include the Edit button in the vlookup table, and instructions to go edit the already existing item (in a new browser tab) and cancel their new item, if needed.

          I hope that helps out.

        • #35868
          SteveE
          Participant

            Agreeing with Keith on this as I would make a field or script that combines the three fields and then check against them.

            Instead of using the native duplicate check you could use a presave. Something like this:

            function dffs_PreSaveAction(){
            var Pass = true;
            var res = spjs.utility.queryItems({
            “listName”:”The List To Check”,
            “query”:”<Where><Eq><FieldRef Name=’Title’ /><Value Type=’Text’>”+getFieldValue(“Title”)+”</Value></Eq></Where>”,
            “viewFields”: [“Title”]
            });
            if(res.count > 0){
            Pass = false;
            }
            if(!Pass){
            spjs.dffs.alert({
            “title”: “”,
            “msg”: “There already is an entry that matches this.<br><br>Please edit the existing entry.”
            });
            return false;
            }
            return true;
            }

        Viewing 2 reply threads
        • You must be logged in to reply to this topic.