Last active
June 29, 2016 19:42
-
-
Save IAMIronmanSam/3dea95087e3d9662bfee4ad5e826de6a to your computer and use it in GitHub Desktop.
Get List items by CAML query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CAMLGetListItems(SPHostUrl,listTitle,query){ | |
var SPContext = new SP.ClientContext.get_current(SPHostUrl); | |
var web = SPContext.get_web(); | |
var List = web.get_lists().getByTitle(listTitle); | |
var listItems; | |
var query = new SP.CamlQuery(query); | |
query.set_viewXml(query); | |
listItems = List.getItems(query); | |
SPContext.load(listItems); | |
SPContext.executeQueryAsync(GetListItems_Successor, GetListItems_Fail); | |
} | |
function GetListItems_Successor(sender, args){ | |
var listItemEnumerator = listItems.getEnumerator(); | |
while (listItemEnumerator.moveNext()){ | |
var oListItem = listItemEnumerator.get_current(); | |
var title = oListItem.get_item('Title'); | |
console.log(title); | |
} | |
} | |
function GetListItems_Fail(err){ | |
console.log('error') | |
} | |
var CAMLQuery = '<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' + | |
'<Value Type=\'Number\'>0</Value></Geq></Where></Query><RowLimit>30</RowLimit></View'; | |
CAMLGetListItems('https://domain.sharepoint.com/teams/mySite/','xyzList',CAMLQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment