web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :

Getting Count of List Items based on a specific condition using JavaScript in SharePoint 2013

Nishant Rana Profile Picture Nishant Rana 11,325 Microsoft Employee

Hi,

Below is the sample script we used to get the total listitems that have MarkAsUnread ( Yes/No) Column value set as No (i.e. 0)


var myItems;

function GetCount() {
 debugger;
 var queryListItem = '<View><Query><Where><Eq><FieldRef Name="MarkAsRead" /><Value Type="Boolean">0</Value></Eq></Where></Query></View>';

 var siteUrl = window.location.protocol + "//" + window.location.host;
 var clientContext = new SP.ClientContext(siteUrl);
 var oList = clientContext.get_web().get_lists().getByTitle('Notification Centre');

var myquery = new SP.CamlQuery();
 myquery.set_viewXml(queryListItem);
 myItems = oList.getItems(myquery);

clientContext.load(myItems);

clientContext.executeQueryAsync(
 Function.createDelegate(this, this.onQuerySucceeded),
 Function.createDelegate(this, this.onQueryFailed)
 );
}

function onQuerySucceeded(sender, args) {

alert(myItems.get_count());
}

function onQueryFailed(sender, args) {

 alert('Request failed. ' + args.get_message() +'\n' + args.get_stackTrace());
}

Hope it helps


Filed under: SharePoint, SharePoint 2010, SharePoint 2013 Tagged: SharePoint, SharePoint 2010, SharePoint 2013

This was originally posted here.

Comments

*This post is locked for comments