SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using a web service and am trying to return the highest ID number from the Posts list with viewname {B9212691-1AF1-41AF-9DA7-6073ADDB091B}. So far I have the following.

<script type="text/javascript">
    $(document).ready(function() {
        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv=''> \
                <soapenv:Body> \
                     <GetListItems xmlns=''> \
                        <listName>Posts</listName> \
                        <viewName>{B9212691-1AF1-41AF-9DA7-6073ADDB091B}</viewName> \
                    <View> \
                        <Query> \
                                 <OrderBy> \
                                <FieldRef Name='ID' Ascending='False' /> \
                             </OrderBy> \
                        </Query> \
                    <RowLimit>1</RowLimit> \
                    </View> \
                    </GetListItems> \
                </soapenv:Body> \

            url: "_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""

    function processResult(xData, status) {
        $(xData.responseXML).find("z\\:row").each(function() {
            var liHtml = "<li>" + $(this).attr("ows_ID") + "</li>";


<ul id="tasksUL"/> 

As is, it returns all the the IDs of the view.

share|improve this question
Does this code work? Are you getting any error? Please, clarify your particular problem. – Andrey Markeev Aug 28 '11 at 22:23
Sorry, left that out. Edited it. – Rick Aug 29 '11 at 13:01

Rick: I answered this for you over on Stack Overflow the other day:

It looks like you've got the OrderBy and RowLimit correct to get what you want. My guess is that you're getting the last ID, but not in the view you want. You probably need to add any additional filtering you are doing in the view into the Query here as well.

p.s. To be compatible with multiple browsers, you should use this selector:


See my post:

EDIT: One other thought: Because you are specifying the RowLimit and Query, you are overriding the normal settings of the view. You could stick with the view specification only, as you had originally, and upon receiving the items in the view, in your .each() loop through and determine the highest ID in your script. Basically, you'd be building your own little MAX function.

share|improve this answer
I left the view in because the latest ID could be hidden and the view has the correct "latest" ID. Thanks for the syntax revision. – Rick Aug 29 '11 at 16:32
Instead of eachfunction() can I just run it once then? Either way the current CAML reteives all view records. – Rick Aug 29 '11 at 16:33
If you remove the query and the rowlimit, you ought to get only the items in the view. – Marc D Anderson Aug 29 '11 at 17:05
But I want just the max ID from my view. – Rick Sep 5 '11 at 23:52

It works fine. I did programatically in SPSevices.

$(document).ready(function() {

    var idquery=""; 
     operation: "GetListItems", 
    async: false, 
    listName: "test", 
    CAMLQuery: idquery, 
    CAMLRowLimit: 1, 
    completefunc: function (xData, Status) 
    $(xData.responseXML).SPFilterNode("z:row").each(function() { //alert($(this).attr("ows_Title")); 
    var getvalue= parseInt($(this).attr("ows_Title"))+1;//Auto increment value $("input[title='TicketNumber']").val(getvalue);

  1. Get value in variable parseInt($(this).attr("ows_Title"))+1;
  2. Bind text box TICKET Number

Click here more details

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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