In this particular example, I'm connecting to a SharePoint list and performing the following activities:
- Filtering the list items that were created within a specified date range while, also, ignoring the time values. NOTE: If you need to include the time values, simply change the IncludeTimeValue attribute from FALSE to TRUE.
- Ordering the list so that it returns the most recently created items first and older items last
var selectedMinDate = '2018-1-1'; var selectedMaxDate = '2018-1-31';
var camlQueryText = "<View><Query><Where><And><Geq><FieldRef Name=\'Created\' /><Value Type=\'DateTime\' IncludeTimeValue=\'FALSE\' >" + selectedMinDate + "</Value></Geq><Lt><FieldRef Name=\'Created\' /><Value Type=\'DateTime\' IncludeTimeValue=\'FALSE\' >" + selectedMaxDate + "</Value></Lt></And></Where><OrderBy><FieldRef Name=\'Created\' Ascending=\'False\' /></OrderBy></Query></View>";
var ctx = new SP.ClientContext.get_current(); var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml(camlQueryText); this.items = ctx.get_web().get_lists().getByTitle('NameOfList').getItems(camlQuery); ctx.load(items); ctx.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); function onQuerySucceeded(sender, args) { while (listItemEnumerator.moveNext()) { var oListItem = listItemEnumerator.get_current(); var itemInfo = oListItem.get_item('Title') + " - " + oListItem.get_item('Created'); alert(itemInfo); } }
function onQueryFailed(sender, args) { alert('request failed ' + args.get_message() + '\n'+ args.get_stackTrace()); }
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.