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

In this article you will learn the pre-save action on document libraries in SharePoint 2013 and Office 365.

Welcome to an article on ‘Pre-Save Action on Document Libraries in SharePoint 2013 and Office 365.’ We developers 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 by passes 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.

    form

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

    main

  • Click on Add a Web Part,

    add

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

    script

  • Click on Edit Snippet, you will see the screen below.

    embed

  • Use the code below and click Ok.

    Code:
    1. <script src="/jquery-1.8.3.min.js" type="text/javascript"></script>  
    2. <script src="/jquery.SPServices-0.7.2.min.js" type="text/javascript"></script>  
    3. <script type"text/javascript">  
    4. $(document).ready(function()  
    5. {   
    6. });  
    7. function PreSaveAction()  
    8. {  
    9. }   
    10. </script>  
    a. Use the function PreSaveAction() and paste your validation under the function on the code.

    b. Before saving document library the code will check your validation and will get saved.
Doesn’t it solve a lot of queries related to document libraries functions? Keep learning!
 
Read more articles on SharePoint: