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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With