locked
How to prevent duplicate items value in sharepoint list?? RRS feed

  • Question

  • Hi,

    Want to prevent items value being duplicate in sharepoint 2007 list in particular Field. i know we can create event handler but is there any other way we can achieve this using UI(like JQuery etc). Because they dont allow custom code.

    Any help will be appreciated.

    Friday, October 12, 2012 5:27 PM

All replies

  • I don't know if using an SPD Workflow is considered custom code, but...

    I'll assume that you're referring to a Category field, and that you have a Category List, of which is used by a Lookup field in the child list, where the user is performing the data entry.

    1. Only allow the user to enter the value in a dummy (vs true) category text field (which exists in the child list, not the Category parent list.)

    2. After entry, use a workflow to determine if the value exists in the Category list.  If so, then assign the proper CategoryID (from the lookup list), to the true (vs dummy) Category lookup field (in the child list, not the Category parent list.)

    3. If the value does not already exist in the Category list, then add it to the Category Parent Lookup list, and then assign it to the true (vs dummy) category lookup field in the child list.

    [edit] I guess I should mention that this does not prevent a dummy from making a speeling[sic] error when adding their category.  Beverage vs. Beverages, etc. [/edit]


    Steve Clark, MCTS | Twin-Soft.com
    Easy Bins Dumpster Rentals of Northern VA. (Specializing in driveway-sized roll-off dumpsters.)
    Be sure to click one of them there forum buttons that artificially inflates my narcissitic ego... I mean gives me points.


    Monday, October 15, 2012 1:25 PM
  • To add onto Mr Clark's answer, you might also make use of the SPServices MakeUnque function.  It IS code but only needs SPD to implement it client side.

    Have a look and see if it'll meet your aims

    http://spservices.codeplex.com/wikipage?title=$%28%29.SPServices.SPRequireUnique&referringTitle=Documentation


    Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/

    Monday, October 15, 2012 4:13 PM
    Answerer
  • Hi Andrews,

    Thanks for your reply. Could you tell me where should i put javascript code(New Form/Edit Form). They said this code wouldn't work with DataSheet view. is there any way i can use this code with Datasheet View?

    Tuesday, October 16, 2012 5:10 PM
  • Hi,

            Put the code in the newform .

    Regards,

    Grigory

    Wednesday, October 17, 2012 7:28 AM
  • As Grigory says, editing the Newform / EditForm with SPD allows the addition of the JQuery code.

    In regards to datasheet view, you're quite right.  The problem that you face is that a new list item automatically generates a new ID and its on this that its uniqueness will be generated.  Since you can't / won't use a server code solution, datasheet view will pretty much allow you to bypass any JScript measures implemented.


    Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/

    Wednesday, October 17, 2012 9:41 AM
    Answerer
  • Grigory/Steven,

    This is the first time I am attempting to modify the aspx code.  When I pasted the following example code, I placed it the first element following <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server"> and saved the page.  I navigated to the SharePoint list to create a new item and it continues to allow duplicate values in the title field.  Any ideas as to what I may be doing incorrectly?

    Cheers 

    <script language="javascript" type="text/javascript" src="../../jQuery%20Libraries/jquery-1.3.2.min.js"></script>
    <script language="javascript" type="text/javascript" src="../../jQuery%20Libraries/jquery.SPServices-0.4.6.min.js"></script>
    <script language="javascript" type="text/javascript">
    	$(document).ready(function() {
    		$().SPServices.SPRequireUnique({	
    			columnStaticName: "Title",
    			duplicateAction: 0,
    			ignoreCase: "false",
    			initMsg: "This value must be unique.",
    			initMsgCSSClass: "ms-vb",
    			errMsg: "This value is not unique.",
    			errMsgCSSClass: "ms-formvalidation"
    		});
    	});
    </script>

    Tuesday, October 23, 2012 3:26 PM
  • Hi Miles,

    Not a problem, lets see what we can do to help.  my first two suggestions are: -

    1. When editing the NewForm.aspx, you've inserted it in the correct place.  Try alt clicking on those links to ensure that the files can be read and access by the form.  If it doesn't work, then the URL is wrong.
    2. Try setting the debug filter to true, so you'll get some more information.  You'll need to amend your cose slightly as to the below
    3. Double check the StaticName.  If you're using the Title field (as your code suggests) then it should be ok with what you've done.
    <script language="javascript" type="text/javascript" src="../../jQuery%20Libraries/jquery-1.3.2.min.js"></script>
    <script language="javascript" type="text/javascript" src="../../jQuery%20Libraries/jquery.SPServices-0.4.6.min.js"></script>
    <script language="javascript" type="text/javascript">
    	$(document).ready(function() {
    		$().SPServices.SPRequireUnique({	
    			columnStaticName: "Title",
    			duplicateAction: 0,
    			ignoreCase: "false",
    			initMsg: "This value must be unique.",
    			initMsgCSSClass: "ms-vb",
    			errMsg: "This value is not unique.",
    			errMsgCSSClass: "ms-formvalidation"
    			debug: true
    		});
    	});
    </script>


    Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/

    Tuesday, October 23, 2012 3:51 PM
    Answerer
  • Thanks Steven.  It appears the second step you outlined is the cause of the problem.  When I attempt to follow the following two src locations I receive "Server error: There is no file with the URL 'jQuery%20Libraries/jquery-1.3.2.min.js' in this Web.

    • ../../jQuery%20Libraries/jquery-1.3.2.min.js
    • ../../jQuery%20Libraries/jquery.SPServices-0.4.6.min.js

    Of note: I am just a site administrator and will never be able to get the farm admin to adjust anything (big company).  Am I out of luck?

    • Edited by miles827 Tuesday, October 23, 2012 4:42 PM
    Tuesday, October 23, 2012 4:41 PM
  • Hi,

    I am having a similar issue in that mine is allowing dups, I want it to be on the Email Address column but for now I am just testing with Title:

    <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
    <script language="javascript" type="text/javascript" src="http://server/JQuery%20Library/jquery-1.9.1.min.js"></script>
    <script language="javascript" type="text/javascript" src="http://server/JQuery%20Library/jquery.SPServices-2013.01.js"></script>
    <script language="javascript" type="text/javascript" src="http://server/JQuery%20Library/jquery.SPServices-2013.01.min.js"></script>
    <script language="javascript" type="text/javascript">
    $(document).ready(function() {
    $().SPServices.SPRequireUnique({
    columnStaticName: "Title",
    duplicateAction: 0,
    ignoreCase: "false",
    initMsg: "This value must be unique.",
    initMsgCSSClass: "ms-vb",
    errMsg: "This value is not unique.",
    errMsgCSSClass: "ms-formvalidation"
    debug: true
    });
    });
    </script>

    <SharePoint:UIVersionedContent UIVersion="4" runat="server">
    <ContentTemplate>
    <div style="padding->
    </ContentTemplate>

    I can get to my Javascript files by clicking on the links, so it's not that. Can you help?

    Thanks


    Wednesday, May 15, 2013 1:39 PM
  • You've set the debug to true.  Are you getting debug box each time you load your page?


    Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/

    Wednesday, May 15, 2013 3:27 PM
    Answerer
  • No, there is no debug box that shows.  It appears as if it would work but then just disregards. 
    Wednesday, May 15, 2013 3:29 PM
  • If the modal pop-up isn't showing, then there's a linking issue to your form.  You've placed them after the ContentHolderMain and you're previewing the right form in SPD?

    Steven Andrews | SharePoint Professional | http://www.twitter.com/backpackerd00d | https://baron72.wordpress.com/

    Wednesday, May 15, 2013 4:11 PM
    Answerer
  • Yes they are in the ContentHolderMain for the newitem.aspx and the edititem.aspx, I got to them by selecting All Files, then lists, the list name and then the .aspx files and edited them in advanced mode. 
    Wednesday, May 15, 2013 6:30 PM