Set Default Mobile View in SharePoint using JSOM

The example in this topic show how to use JSOM to Set Default Mobile View in SharePoint

  • function SetDefaultMobileView() {
  •     // 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();
  •  
  •     // Get List Object
  •     var olistCollection = clientContext.get_web().get_lists();
  •     var oList = olistCollection.getByTitle("List Name");
  •  
  •     // Get required view by specifying view Title here
  •     var oView = oList.get_views().getByTitle('Custom View2');
  •  
  •     // Make this view the default view for mobile access
  •     oView.set_mobileDefaultView(true);
  •  
  •     // Update View
  •     oView.update();
  •  
  •     // Execute the query to the server.
  •     clientContext.executeQueryAsync(onsuccess, onfailed);
  • }
  •  
  • function onsuccess() {
  •     console.log('Success');
  • }
  •  
  • function onfailed(sender, args) {
  •     console.log('Failed' + args.get_message() + '\n' + args.get_stackTrace());
  • }

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


© 2019 Code SharePoint