locked
How to make attachment required field?

    Question

  • We would like to create a custom list and require user to attach a scanned form. How do we make the attachment a required field? Also, when creating new column, there is no column for attachment type. Is it possible to attache multiple files to a record? Thanks.
    Wednesday, July 30, 2008 2:52 PM

Answers

  •  <script type="text/javascript" language="javascript">
    function PreSaveAction() {
    
    	        var elm = document.getElementById("idAttachmentsTable");
    	        if (elm == null || elm.rows.length == 0)
    {
    	            document.getElementById("idAttachmentsRow").style.display='none';
    
    alert("Please attach Documents");
    return false ;
    }
    else { return true ;}
    }
    </script>
    

    • Proposed as answer by Siva Chundru Wednesday, December 23, 2009 5:50 PM
    • Unproposed as answer by Mike Walsh FIN Wednesday, April 07, 2010 5:42 AM
    • Proposed as answer by Aysha Al Dhaheri Friday, August 27, 2010 10:49 AM
    • Marked as answer by Mike Walsh FIN Wednesday, June 15, 2011 6:33 AM
    Wednesday, December 23, 2009 5:50 PM
  • the supported method would be to use a document library, so as the scanned files are uploaded you then tag them.

    Using a list item it is not possible to make the attachment required out of the box. We have written JScript to do this in the past. The attachments names are stored in a hidden DIV in the New Item form. It is easy to check if anything has been added to the DIV. You can also check the file type extensions being used in this DIV. You just need to place your JScript code in a Content Editor Web Part.

    Not the best solution, but it will do the trick.

    Regards,
    James.
    Wednesday, July 30, 2008 9:23 PM

All replies

  • I don't think you make an attachment mandatory through the user interface.

    You may be able to use an event receiver (requires code) or use infopath.

    --Paul Galvin of www.Conchango.com @ http://feeds.feedburner.com/PaulGalvinsSharepointSpace
    Wednesday, July 30, 2008 4:30 PM
  • the supported method would be to use a document library, so as the scanned files are uploaded you then tag them.

    Using a list item it is not possible to make the attachment required out of the box. We have written JScript to do this in the past. The attachments names are stored in a hidden DIV in the New Item form. It is easy to check if anything has been added to the DIV. You can also check the file type extensions being used in this DIV. You just need to place your JScript code in a Content Editor Web Part.

    Not the best solution, but it will do the trick.

    Regards,
    James.
    Wednesday, July 30, 2008 9:23 PM
  •  <script type="text/javascript" language="javascript">
    function PreSaveAction() {
    
    	        var elm = document.getElementById("idAttachmentsTable");
    	        if (elm == null || elm.rows.length == 0)
    {
    	            document.getElementById("idAttachmentsRow").style.display='none';
    
    alert("Please attach Documents");
    return false ;
    }
    else { return true ;}
    }
    </script>
    

    • Proposed as answer by Siva Chundru Wednesday, December 23, 2009 5:50 PM
    • Unproposed as answer by Mike Walsh FIN Wednesday, April 07, 2010 5:42 AM
    • Proposed as answer by Aysha Al Dhaheri Friday, August 27, 2010 10:49 AM
    • Marked as answer by Mike Walsh FIN Wednesday, June 15, 2011 6:33 AM
    Wednesday, December 23, 2009 5:50 PM
  • This is almost exactly what I was looking for as well. Thank you. Is there a way to add this to a list containing two separate content types? My list captures requests and has two content types - one for individual requests and one for bulk requests. I'd like to have the form require an attachment only for the bulk request - but this seems to act on the list level irregardless of which form is displayed.
    Friday, January 01, 2010 4:44 AM
  • My last post was not so clear. Is there a way to limit this content editor web part script to a specific content type? Something along the lines of "Where ContentTypeID= xxx..." ? I'm trying to get this script only to run with one of two content types on my list. Or is my only alternative to create a separate newform.aspx page for each content type?
    Monday, January 04, 2010 4:07 PM
  • Thanks Hallelajuh, Your script works excellent.

    Regards,

    Suresh Kumar Udatha.

    Wednesday, April 07, 2010 5:22 AM
  • Hallelajuh:

     

    Please do not propose your own posts as answers. It isn't helpful.

    Propose the good answers of other people and wait for someone else to propose your posts.

     

    (Moderator)


    FAQ sites: (SP 2010) http://wssv4faq.mindsharp.com; (v3) http://wssv3faq.mindsharp.com and (WSS 2.0) http://wssv2faq.mindsharp.com
    Complete Book Lists (incl. foreign language) on each site.
    Wednesday, April 07, 2010 5:43 AM
  • Hi Hallelajuh

    please explain where this code should be added?

    Tuesday, May 11, 2010 4:02 AM
  • This code worked for me.

    Aysha, to add the code follow the steps below;

    1. Add a Content Editor Web Part at the bottom of the form ( You might need to do this in SPD).

    2. Click Source Editor Button and place the coding.

    Saturday, May 22, 2010 8:39 AM