0

Can you please help? I don't know what i am doing wrong here. Also i have column name that has spaces "File Status". How to write that in the code

 <script type="text/javascript">
    var siteurl = _spPageContextInfo.webAbsoluteUrl;
            $.ajax({
                       url: siteurl + "/_api/web/lists/getbytitle('VolunteerMasterList')/items",
                       method: "GET",
                       headers: { "Accept": "application/json; odata=verbose" },
                       success: function (data) {
                            if (data.d.results.length > 0 ) {
                                    var sum =0;
                                    var sum1 =0;
                                    var sum2 =0;
                                    var sum3 =0;
                                    $.each(data.d.results, function(item){
                                        if(item.City === "Earth")
                                          sum++;
                                        if(item.VolunteerMasterListFileStatus === "Closed")
                                          sum1++;
                                        if(item.VolunteerMasterListFileStatus === "Partial")
                                          sum2++;
                                        if(item.VolunteerMasterListFileStatus === "Special Project")
                                          sum3++;
                                    });                             
                            }
    document.getElementById("myelement").innerHTML=sum;
                      },
                      error: function (data) {
                          alert("Error: "+ data);
                     }
              });
    </script>
0

Use Field static name.

Sample script:

 <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
 <script type="text/javascript">
    var siteurl = _spPageContextInfo.webAbsoluteUrl;
            $.ajax({
                       url: siteurl + "/_api/web/lists/getbytitle('VolunteerMasterList')/items",
                       method: "GET",
                       headers: { "Accept": "application/json; odata=verbose" },
                       success: function (data) {
                            if (data.d.results.length > 0 ) {
                                    var sum =0;
                                    var sum1 =0;
                                    var sum2 =0;
                                    var sum3 =0;
                                    $.each(data.d.results, function(index,item){
                                        if(item.City === "Earth")
                                          sum++;
                                        if(item.File_x0020_Status === "Closed")
                                          sum1++;
                                        if(item.File_x0020_Status === "Partial")
                                          sum2++;
                                        if(item.File_x0020_Status === "Special Project")
                                          sum3++;
                                    }); 
                                    console.log(sum);
                                    console.log(sum1);
                                    console.log(sum2);
                                    console.log(sum3);
                            }
                        document.getElementById("myelement").innerHTML=sum;
                      },
                      error: function (data) {
                          alert("Error: "+ data);
                     }
              });
    </script>

    <div id="myelement"></div>

This is i am doing finally

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
 <script type="text/javascript">
    var siteurl = _spPageContextInfo.webAbsoluteUrl;
            $.ajax({
                       url: siteurl + "/_api/web/lists/getbytitle('Volunteer%20Master%20List')/items",
                       method: "GET",
                       headers: { "Accept": "application/json; odata=verbose" },
                       success: function (data) {
                            if (data.d.results.length > 0 ) {
                                    var sum =0;
                                    var sum1 =0;
                                    var sum2 =0;
                                    var sum3 =0;
                                    $.each(data.d.results, function(index,item){
                                        if(item.File_x0020_Status  === "Active")
                                          sum++;
                                        if(item.File_x0020_Status === "Closed")
                                          sum1++;
                                        if(item.File_x0020_Status === "Partial")
                                          sum2++;
                                        if(item.File_x0020_Status === "Special Project")
                                          sum3++;
                                    }); 
                                    console.log(sum);
                                    console.log(sum1);
                                    console.log(sum2);
                                    console.log(sum3);
                            }
                        document.getElementById("myelement").innerHTML=sum;
document.getElementById("myelement1").innerHTML=sum1;
document.getElementById("myelement2").innerHTML=sum2;
document.getElementById("myelement3").innerHTML=sum3;
                      },
                      error: function (data) {
                          alert("Error: "+ data);
                     }
              });
    </script>

    <div id="myelement"></div>
<div id="myelement1"></div>
<div id="myelement2"></div>
<div id="myelement3"></div>
  • The script works perfectly fine. Thanks for helping out. The only problem i have that there are 319 entries but the total item count for each shows 21,77,2,0 – Mani Nov 25 at 21:00
  • Any idea please why my Totals are not matching, – Mani Nov 26 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.