Retrieve All List Properties in SharePoint 2013 Using JavaScript (JSOM)

This article shows how to write code to perform basic operations using the JavaScript client object model in SharePoint 2013.

You can use the SharePoint client object model to retrieve, update and manage data in SharePoint 2013. SharePoint makes the object model available in several forms.

  • .NET Framework redistributable assemblies.
  • JavaScript library.
  • REST/OData endpoints.
  • Windows Phone assemblies.
  • Silverlight redistributable assemblies.

This article shows how to perform basic operations using the JavaScript object model. You can add a reference to the object model using HTML <script> tags.

The following sections describe tasks that you can complete programmatically and they include JavaScript code examples that show the operations.

Procedure

Open your SP Site in SharePoint 2013 Designer. Then select the Assets icon in the designer ribbon to add a JavaScript file.



After adding the JavaScript file the file is available in the SharePoint Site Assets Folder.



Go to the SP site Page and add a new page to the SharePoint site.





After adding a page, select an Insert button in the Ribbon Menu.



Then add a Content Editor Web part into the page.



Edit the WebPart and add a JavaScript file link to the content link.



Save the web part and save the page in the site. Click the button.



List Created Successfully

Source Code

  1. < div > < button onclick = " retrieveAllListProperties ()" > Click here to AddaFieldtoList < /button></div >  
  2.   
  3. < div id = "displayDiv" > < /div>  
  4. <script type="text/javascript  
  5. ">   
  6. function retrieveAllListProperties()  
  7. {  
  8. var siteUrl="  
  9. https: //gauti.sharepoint.com/sites/sp";  
  10. var clientContext = new SP.ClientContext(siteUrl);  
  11. var oWebsite = clientContext.get_web();  
  12. this.collList = oWebsite.get_lists();  
  13. clientContext.load(collList);  
  14.   
  15. clientContext.executeQueryAsync(  
  16.    Function.createDelegate(thisthis.onQuerySucceeded),  
  17.    Function.createDelegate(thisthis.onQueryFailed));  
  18. }  
  19.   
  20. function onQuerySucceeded()   
  21. {  
  22.     var listInfo = '';  
  23.     var listEnumerator = collList.getEnumerator();  
  24.   
  25.     while (listEnumerator.moveNext())   
  26.     {  
  27.         var oList = listEnumerator.get_current();  
  28.         listInfo += 'Title: ' + oList.get_title() + ' Created: ' + oList.get_created().toString() + '\n';  
  29.     }  
  30.     alert(listInfo);  
  31. }  
  32.   
  33. function onQueryFailed(sender, args)  
  34. {  
  35.     alert('Request failed. ' + args.get_message() +  
  36.         '\n' + args.get_stackTrace());  
  37. }   
  38. < /script>  
Thanks for reading my article.