I have a list . I want select items of list with a special quary.(get items that created with current user). Then get count of items.
I use this code for get current user :
function Initialize()
{
context = new SP.ClientContext.get_current();
web = context.get_web();
var currentUser = web.get_currentUser();
alert(currentUser);
currentUser.retrieve();
context.load(web);
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),
Function.createDelegate(this, this.onFailureMethod));
}
function onSuccessMethod(sender, args) {
var userObject = web.get_currentUser();
alert('User name:' + userObject.get_title() + '\n Login Name:' +
userObject.get_loginName());
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
But don't get current user.
and use this code for get items of list.
function Initialize()
{
clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();
var list = web.get_lists().getByTitle("Sends");
var camlQuery = new SP.CamlQuery();
var q = "<Where><Eq><FieldRef Name='CreatedUser' /><Value Type='User'>CurrentUser</Value></Eq></Where>";
camlQuery.set_viewXml(q);
this.listItems = list.getItems(camlQuery);
clientContext.load(listItems, 'Include(ID)');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess),
Function.createDelegate(this, this.onQueryFailed));
}
function onListItemsLoadSuccess(sender, args) {
var count = 0;
count = this.listItems.get_count();
}
function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}