How to Validate Attachment Field in SharePoint 2010,2013,2016 and SharePoint online?

Hello Fellow SharePointers,

In this blog, I would like to write about a validation scenario where you need to check if your attachment field has attachments or not. In SharePoint 2010 and 2013, a custom list can have attachments. You can add attachment field using Infopath form as well. Whatever the case may be, If you want to validate the attachment field type.here is the JavaScript to be placed either in custom form with the help of SharePoint Designer  or you can add the scripts using content editor web part.

function PreSaveAction() {

var attach= document.getElementById(“idAttachmentsTable”);
if (attach== null || attach.rows.length == 0)
{
document.getElementById(“idAttachmentsRow”).style.display=’none’;

alert(“Please attach Documents in the Attachment Section.It is Mandatory”);
return false ;
}
else { return true ;}
}
</script>

Happy SharePointing 🙂

 

Leave a Reply

Your email address will not be published. Required fields are marked *