How to read the value of a SharePoint list item (current item) using javascript

I need to read Title and Location from an image library and display using CEWP.

Can someone suggest how to read the values โ€‹โ€‹of a SharePoint list item using Javascript.

+4
source share
5 answers

You can use the JavaScript Client object model. Assuming the window _spPageContextInfo object is set with the initialized properties webServerRelativeUrl , pageListId and pageItemId :

 var context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl); var list = context.get_web().get_lists().getById(_spPageContextInfo.pageListId); var item = list.getItemById(_spPageContextInfo.pageItemId); 

Then you can load the required fields:

 context.load(item, "Title", "Location"); context.executeQueryAsync(Function.createDelegate(this, this.mySuccessFunction), Function.createDelegate(this, this.myErrorFunction)); 

item will now be filled in with the fields you requested, and you can get them like this:

 var itemTitle = item.get_item("Title"); var itemLocation = item.get_item("Location"); 

Note that you must use the display, not internal, names of the fields you want to load.

+15
source

In SharePoint 2010, there are three different types of client model extensions that you can use. This is a managed client object model, an extension of ECMAScript and silverlight.

This link is closer to your requirement. How to get lists using JavaScript and How to get the current list item in JavaScript?

SP.ListOperation.Selection Methods

 var value = SP.ListOperation.Selection.getSelectedItems(); 

Check out the following links for more information:
SharePoint 2010: Use ECMAScript to Manage (Add / Remove / Update / Retrieve) List Items
Access List Data Using a JavaScript Client
Using the SP2010 client object model to update a list item How to do - SharePoint 2010 - JS client object model and user interface improvements

+3
source

You can use jQuery to access list items through SharePoint web services. See Here Here - SharePoint Web Services with jQuery

+2
source
 if _spPageContextInfo.pageItemId is undefined. Use this function function getUrlVars() { var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for (var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; } //THEN DO THIS var id = getUrlVars()["ID"]; //THEN DO YOUR MAGIC var context = new SP.ClientContext(_spPageContextInfo.webServerRelativeUrl); var list = context.get_web().get_lists().getById(_spPageContextInfo.pageListId); var item = list.getItemById(id); 
+1
source

SP2010 introduces new client APIs that allow you to interact with SharePoint sites from JavaScript

SharePoint 2010 Client Object Model

JavaScript class library

-1
source

Source: https://habr.com/ru/post/1383768/


All Articles