Modify Default Error Message – Duplicates

Forums General discussion Modify Default Error Message – Duplicates

Viewing 3 reply threads
  • Author
    Posts
    • #37506
      Sarah O
      Participant

      Hello,

      I have ‘Enforce Unique Values’ selected on my SP list in the Name field settings. The default error message upon saving is ‘This value already exists in the list.’. Can this be modified to be more specific to my use-case?

      Attachments:
    • #37508
      Alexander Bautz
      Keymaster

      Sorry, but I don’t have any method of overriding this message as it is a built in message in the out-of-the-box sharepoint.

      Alexander

    • #37511
      Sarah O
      Participant

      Is there a way to create a rule that will enforce unique values for a field and it will display an alert message in the rule if field is not unique upon save?

    • #37513
      Alexander Bautz
      Keymaster

      The only way to do this if you don’t want to use the built in method is to have a query that runs pre-save to check for duplicate values. This is pretty straight forward if the list does have to many items. If you exceed a few thousands items, the query would slow down the save process because it has to wait for the query to return.

      Basically you can use something like this in your custom js:

      function dffs_PreSaveAction(){
          var res = spjs.utility.queryItems({
              "listName": _spPageContextInfo.pageListId,
              "query": ""+getFieldValue("Title")+""
          });
          if(res.count > 0){
              spjs.dffs.alert({
                  "title": "Duplicate value",
                  "msg": "An item with this title already exist, please change the value and try again.",
                  "ok": function(){
                      // Close dialog
                  }
              });
              return false;
          }
          return true;
      }
      

      Alexander

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