Counting listitems multiple times with javascript
<p>I'm using JS to get the number of (filtered) listitems to show on a dashboard. My functions work well when I call them once but I need to call them multiple times. Only the last call is processed. What am I doing wrong here?</p>

<pre><code>ExecuteOrDelayUntilScriptLoaded(SetNumbers, "sp.js");
var clientContext = null;
var web = null;

function SetNumbers(){
CountProjecten("Project","#pbabbm",12);
CountProjecten("Project","#pbabne",14);
CountProjecten("Project","#pbabta",13);
CountProjecten("Project","#pbabti",15);
CountProjecten("Project","#pbabsw",21);
CountProjecten("Project","#pbabsbew",20);
CountProjecten("Project","#pbabblt",19);
CountProjecten("Project","#pbaknmct",1);
CountProjecten("Project","#pbakdevine",2);
CountProjecten("Project","#pbakom",9);
CountProjecten("Project","#pbakjrn",18);
CountProjecten("Project","#pbakcm",10);
CountProjecten("Project","#pbaktrm",7);
}


function CountProjecten(listName, divId, opleidingId)
{

clientContext = new SP.ClientContext.get_current();
web = clientContext.get_web();        
var list = web.get_lists().getByTitle(listName);        
var camlQuery = new SP.CamlQuery();        
var q = "&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;And&gt;&lt;Eq&gt;&lt;FieldRef Name='Status' LookupId='True' /&gt;&lt;Value Type='Lookup'&gt;3&lt;/Value&gt;&lt;/Eq&gt;&lt;Eq&gt;&lt;FieldRef Name='Opleiding' LookupId='True' /&gt;&lt;Value Type='LookupMulti'&gt;" + opleidingId + "&lt;/Value&gt;&lt;/Eq&gt;&lt;/And&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;";
camlQuery.set_viewXml(q);
this.listItems = list.getItems(camlQuery);
this.divId=divId;
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();
$(this.divId).text(count);
}

function onQueryFailed(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
</code></pre>
