Share via


SharePoint 2013 And Office 365: Pre-Save Action on Document Libraries

Developers can face an issue when our client wants to have an action done on a document library on a save click.

Document Library uploads the document, and to validate something on the save click is tricky as the save bypasses the validation and gets saved.

Solution

The solution to do any JavaScript validation is Pre Save action. So here is what you need to do.

Open your Document Library

Under the ‘Library’ tab, click on the Form Web Parts.

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/pre-save-action-on-document-libraries-in-sharepoint-2013-and/Images/image002.png

Choose Default Edit Form, you will see the screen below.

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/pre-save-action-on-document-libraries-in-sharepoint-2013-and/Images/image003.png

Click Add a Web Part,

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/pre-save-action-on-document-libraries-in-sharepoint-2013-and/Images/image004.png

Choose Script Editor, under the Media and Content Web part.

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/pre-save-action-on-document-libraries-in-sharepoint-2013-and/Images/image005.png

Click Edit Snippet, you will see the screen below.

http://csharpcorner.mindcrackerinc.netdna-cdn.com/article/pre-save-action-on-document-libraries-in-sharepoint-2013-and/Images/image006.png

Use the code below and click OK.

Code:

<script src="/jquery-1.8.3.min.js" type="text/javascript"></script> 

<script src="/jquery.SPServices-0.7.2.min.js" type="text/javascript"></script> 

<script type"text/javascript">  ``$(document).ready(function() 

{  ``});  ``function PreSaveAction() 

{  ``}  ``</script> 

Use the function **PreSaveAction() **and paste your validation under the function on the code.

Before saving the document library the code will check your validation and will get saved.

a

Doesn’t it solve a lot of queries related to document libraries functions? Keep learning!