Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read sharePoint List item value (current Item) using javascript

I have to read Title and Location from a picture library and display using CEWP.

Can someone suggest how to read SharePoint list item values using Javascript.

like image 710
SP10 Avatar asked Dec 01 '22 01:12

SP10


2 Answers

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

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 fields you need:

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

item will now be populated with the fields you requested, and you can retrieve them like so:

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

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

like image 117
vmdominguez Avatar answered Dec 04 '22 07:12

vmdominguez


In SharePoint 2010 there are three different types of Client Object Model extension you can use. They are Managed Client Object Model, ECMAScript and silverlight extension.

This link more close to your requirement How to: Retrieve Lists Using JavaScript and How do you get the current list item in JavaScript?

SP.ListOperation.Selection Methods

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

Check following links for more information:
SharePoint 2010: Use ECMAScript to manipulate (Add/Delete/Update/Get) List Items
Accessing List Data using the JavaScript Client OM
Using the SP2010 Client Object Model to update a list item How to – SharePoint 2010 – JS client object model and UI advancements

like image 34
Niranjan Singh Avatar answered Dec 04 '22 07:12

Niranjan Singh