Home › Forums › General discussion › Modify Default Error Message – Duplicates
- This topic has 3 replies, 2 voices, and was last updated 1 year, 8 months ago by
Alexander Bautz.
-
AuthorPosts
-
-
February 21, 2024 at 17:10 #37506
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:
-
February 21, 2024 at 23:00 #37508
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
-
February 22, 2024 at 16:52 #37511
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?
-
February 22, 2024 at 17:39 #37513
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": "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>"+getFieldValue("Title")+"</Value></Eq></Where>" }); 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
-
This reply was modified 7 months, 2 weeks ago by
Alexander Bautz. Reason: Fixed caml query
-
This reply was modified 7 months, 2 weeks ago by
-
-
AuthorPosts
- You must be logged in to reply to this topic.
