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 an Assets icon from the designer ribbon to add a JavaScript file.
After adding a JavaScript file, the following 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 site. Click the button!
List Created Successfully.
Source Code
- <div><button onclick=" queryListItems ()">Click here to Create a List</button></div>
- <div id="displayDiv"></div>
- <script type="text/javascript">
- //This example gets all the items in the Announcements list that have a title that begins with 'T'.
- //If your site doesn't include a list called Announcements you must make the changes indicated
- //This variable will hold a reference to the Announcements list items collection
- var returnedItems = null;
- //This function loads the list and runs the query asynchronously
- function queryListItems() {
- //Get the current context
- var context = new SP.ClientContext();
- //Get the Announcements list. Alter this code to match the name of your list
- var list = context.get_web().get_lists().getByTitle('Announcements');
- //Create a new CAML query
- var caml = new SP.CamlQuery();
- //Create the CAML that will return only items with the titles that begin with 'T'
- caml.set_viewXml("<View><Query><Where><BeginsWith><FieldRef Name='Title' /><Value Type='Text'>T</Value></BeginsWith> </Where></Query></View>");
- //Specify the query and load the list oject
- returnedItems = list.getItems(caml);
- context.load(returnedItems);
- //Run the query asynchronously, passing the functions to call when a response arrives
- context.executeQueryAsync(onSucceededCallback, onFailedCallback);
- }
- //This function fires when the query completes successfully
- function onSucceededCallback(sender, args) {
- //Get an enumerator for the items in the list
- var enumerator = returnedItems.getEnumerator();
- //Formulate HTML from the list items
- var markup = 'Items in the Announcements list that start with "T": <br><br>';
- //Loop through all the items
- while (enumerator.moveNext()) {
- var listItem = enumerator.get_current();
- markup += 'Item Title: ' + listItem.get_item('Title') + '<br>';
- markup += 'Item ID: ' + listItem.get_id() + '<br><br>';
- }
- //Display the formulated HTML in the displayDiv element
- displayDiv.innerHTML = markup;
- }
- //This function fires when the query fails
- function onFailedCallback(sender, args) {
- //Formulate HTML to display details of the error
- var markup = '<p>The request failed: <br>';
- markup += 'Message: ' + args.get_message() + '<br>';
- //Display the details
- displayDiv.innerHTML = markup;
- }
- </script>
Thanks for reading my article.


Netaji JunghariPosted Oct 22, 2019, 12:57 AM EDT
Hi Gowtham, i have created SP library (OOTB) and stored some records. now im looking for solution if i filter with any unique column then those result will be display.
marwa kallelPosted May 22, 2019, 9:19 AM EDT
Hello , I have a SP account and I need to get data from it to my .net application, what should I use to do that , thank you
Eder SantanaPosted May 29, 2017, 11:37 AM EDT
The page is posting back. The result appears but the page refresh after the click event.
venkat nareshPosted Mar 8, 2017, 10:24 PM EST
Gowtham did you notice the source code is different from the one in the image.
Guest UserPosted Feb 27, 2017, 9:26 PM EST
It's not working. I got request failed error when I tried to pull this code on a CEWP added on a site page.
Gowtham RajamanickamTOP 100Posted Apr 26, 2016, 5:01 AM EDT
thanku all
Sr KarthigaPosted Apr 26, 2016, 4:53 AM EDT
good one sir
Rajkiran SwainPosted Mar 13, 2016, 6:30 AM EDT
nice
SriramPosted Jul 5, 2015, 9:48 PM EDT
Excellent,..............
Vijay SPosted Apr 28, 2015, 11:11 PM EDT
Nice Article
Karthik Muthu KaruppanPosted Apr 23, 2015, 7:24 AM EDT
good
Rahul Kumar SaxenaTOP 100Posted Apr 20, 2015, 10:00 AM EDT
Good Work..
Sibeesh VenuTOP 100Posted Apr 20, 2015, 2:39 AM EDT
good one.
Prasad PathakPosted Apr 19, 2015, 11:34 PM EDT
Nice article
Shantha Kumar TTOP 100Posted Apr 19, 2015, 4:58 PM EDT
Gowtham, my suggestion is to use the html file extension instead of using js extension. That file has the combination of html elements and scripts, even we can use the CSS codes also in the file. Good work. Keep it up....
Santhakumar MunuswamyPosted Apr 19, 2015, 11:55 AM EDT
Good work