Prerequisites.
A sharepoint list:
SharePoint List Name : ItemsSharePoint
Fields:
- Title = Single line of text.
- TextColumn = Single line of text.
1. Insert a content editor webpart, into a principal page. (see next image).
2. Open new notepad and paste the next code.
Read Items Title
<br/>
<INPUT TYPE="button" VALUE="Read Items" onClick="ReadItem()">
<script type="text/javascript">
var siteUrl = '/sites/ejemplossharepoint';
var ListItems;
function ReadItem()
{
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('ItemsSharePoint');
var query = new SP.CamlQuery();
query.set_viewXml("<View><Query><ViewFields><FieldRef Name='Title' /></ViewFields><ViewFields><FieldRef Name='Title' /></ViewFields></Query></View>");
ListItems= oList.getItems(query);
clientContext.load(ListItems);
clientContext.executeQueryAsync(Function.createDelegate(this, this.Succeeded), Function.createDelegate(this, this.Failed));
}
function Succeeded() {
var listEnumerator = ListItems.getEnumerator();
while (listEnumerator.moveNext()) {
alert("Text of list item : " + listEnumerator.get_current().get_item("Title") + listEnumerator.get_current().get_item("TextColumn"));
}
}
function Failed(sender, args) {
alert('Error: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}
</script>
3. Save the notepad in a document library as "CodeRead" and then copu Shortcut (see next image).
4. Edit content editor web part, and paste the link into "content link".
5. Test.
easily.
Regards.
Oscar Miguel Dominguez Acevedo
Cool Article, but can you please provide full script on read multiple columns in sheet or table using JavaScript.
ResponderEliminarSure Mahmoud, give me a few hours to post a article.
EliminarRegards and thanks.
Oscar