0

I have a Sample list named as LISTA. In which i have title column, the title column values are

Title
  A
  b
  c
  A
  b
  c
  c

I need to take the count of item count of a,b,c. using soap services.

Output:

A=2
b=2
c=3

1
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>

    <script type="text/javascript" src="Path to jQuery/jquery-1.8.3.min.js"></script>

<script type="text/javascript">
$(document).ready(function() 
{

    var soapEnv =
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
            <soapenv:Body> \
                 <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                    <listName>your list name</listName> \
                    <viewFields> \
                        <ViewFields> \
                           <FieldRef Name='Title' /> \
                       </ViewFields> \
                    </viewFields> \
                </GetListItems> \
            </soapenv:Body> \
        </soapenv:Envelope>";

    $.ajax({
        url: "http://your sharepoint web/_vti_bin/lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=\"utf-8\""
    });
});

function processResult(xData, status) {
    var liHtml = "";
    var titleArray = {}
    var titles = [];


    $(xData.responseXML).find("z\\:row").each(function () {

        if (typeof titleArray[$(this).attr("ows_Title")] === 'undefined') {
            titleArray[$(this).attr("ows_Title")] = 1;
            titles.push($(this).attr("ows_Title"));
        }
        else {
            titleArray[$(this).attr("ows_Title")]++;
        }


    });

    for (var i = 0; i < titles.length; i++) {
        liHtml += "<li>" + titles[i] + "=" + titleArray[titles[i]] + "</li>";
    }
    $("#Results").html(liHtml);
}

</script>
</head>
<body>
<div id="Results">
</div>

</body>
</html>

Where Path to jQuery is wherever you normally access jQuery from, your sharepoint web is the web/site where your list resides, and your list name is the name of your list.

  • Hi jared Mcgrath, I need to display as below format. can you help me plz. – user876869 May 19 '14 at 13:30
  • Titles A b c Total 2 2 3 – user876869 May 19 '14 at 13:32
  • In table format Title A b c in the first row and Total 2 2 3 in the second row. Please help. thanks in advance.. – user876869 May 19 '14 at 13:38

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.