Set Draft Item Security in SharePoint using JSOM

The example in this topic show how to use JSOM to Set Draft Item Security in SharePoint

  • function SetDraftItemSecurity() {
  •     // You can optionally specify the Site URL here to get the context
  •     // If you don't specify the URL, the method will get the context of the current site
  •     // var clientContext = new SP.ClientContext("http://MyServer/sites/SiteCollection");
  •     var clientContext = new SP.ClientContext();
  •  
  •     var listCollection = clientContext.get_web().get_lists();
  •     var list = listCollection.getByTitle("Documents");
  •  
  •     // Drafts are minor versions or items which have not been approved.
  •     // Specify which users should be able to view drafts in this list.
  •     // Note: If you disable "Content Approval" on the list, "Draft Item Security" option will also get disabled
  •     // Here you can specify one of the option from (1) Approver, (2) Author or (3) Reader      
  •     list.set_draftVersionVisibility(SP.DraftVisibilityType.approver);
  •  
  •     list.update();
  •  
  •     // Execute the query to the server.
  •     clientContext.executeQueryAsync(Function.createDelegate(this, this.onsuccess), Function.createDelegate(this, this.onfailed));
  • }
  •   
  • function onsuccess() {
  •     console.log("success");
  • }
  •  
  • function onfailed(sender, args) {
  •     console.log('Creation Failed' + args.get_message() + '\n' + args.get_stackTrace());
  • }

Thank you for reading this article. This code was tested in SharePoint 2013

We value your feedback:

Page URL:

Name:

 

Email:

 
 

Feedback:

 

© 2019 Code SharePoint