How to Checkin the Page in SharePoint 2013 using Javascript

After the Success of the Check in, the Page should re-load and make sure that its been checked in.

Steps:
  1. Open your SharePoint site  and add a CEWP.

  2. Then Copy the below Code and  call this function on button click. 
  1. <script type="text/javascript">  
  2.    
  3. function checkIn_Success(sender, args)  
  4.           {  
  5.               window.location.reload();  
  6.           }  
  7.           function checkIn_fail(sender, args)  
  8.           {  
  9.             alert('Checkin Failed');  
  10.           }  
  11.           function checkIn()  
  12.           {  
  13.               var ctx = SP.ClientContext.get_current();  
  14.               var web = ctx.get_web();  
  15.               var page = web.getFileByServerRelativeUrl(window.location.pathname);  
  16.                   
  17.                 var listItem = page.get_listItemAllFields();  
  18. //We can set any value to any of the property by the below lines.  
  19.                 //listItem.set_item('PublishingPageContent', '{Updated with ECMA}');  
  20.                 listItem.update();  
  21.                   
  22.               page.checkIn();  
  23.               page.publish();  
  24.               ctx.executeQueryAsync(Function.createDelegate(this, checkIn_Success),Function.createDelegate(this, checkIn_fail));  
  25.           }  
  26. </script>  
Thanks For reading my blogs!!!. 
Ebook Download
View all
Learn
View all