I was wondering how can I count list items. I have done this with C# and I have the following code:
SPWeb thisWeb = SPContext.Current.Web;
SPList vlist = thisWeb.Lists["Vacancies"];
SPListItemCollection listitems = vlist.GetItems();
int sum = 0;
int sum1 = 0;
int sum2 = 0;
foreach (SPListItem item in listitems)
{
if (item["Status"].ToString() == "Completed")
{
sum++;
}
if (item["Status"].ToString() == "In progress")
{
sum1++;
}
if (item["Status"].ToString() == "Rejected")
{
sum2++;
}
}
This code works perfect, how can I convert this code into JavaScript
to do the same function?
I have 3 Statuses
- Completed
- In progress
- Rejected
So int sum
should represent the number of items with Completed
Status
,
int sum1
should represent the number of items with In progress
Status
, and
int sum2
should represent the number of items with Rejected
Status
.
The name of list is Vacancies
Please help me! Thanks
item["StatusCount"] = sum.ToString(); item.Update();
thats it. (I supposed that you have a column called 'StatusCount'). I don't know whether this is for what you are looking.