I am working on a script that needs to pull the SharePoint list item ID from the current row. I have a checkbox field in a multi-item form webpart that, when checked, needs to update the item without having users click "Save." I am aware of how to update the item with SPServices's UpdateListItems, but I need to capture the individual list item id (ows_ID) from that row to pass to SPServices.

I would appreciate someone pointing me in the right direction.


It may not be a pretty solution, but I did find a way to retrieve the list item ID. The first thing I had to do was pull an identifing column for that row. I was able to do this with the "Title" column, which is unique per user.

var taskDesc= $($(this).closest('tr').children(":first")).eq(0).text();

I then used CAML and SPServices to narrow down the items, find the ID and, finally, update the item in the other list. Through javascript I already retrieved current user and put in variable "loginName."

function completeSelectedTask(taskDesc)  {
    var soapEnv =   "<soap:Envelope xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> <soap:Body>" + 
                    "<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>" +
                        "<listName>myListName</listName>" +
                        "<query> <Query> <Where><And>" +
                            "<Eq> <FieldRef Name='Assignee'/> <Value Type='Text'>" + loginName + "</Value> </Eq>" +
                            "<Eq> <FieldRef Name='Title'/> <Value Type='Text'>" + taskDesc + "</Value> </Eq>" +
                        "</And></Where> </Query> </query>" +
                        "<viewFields> <ViewFields> <FieldRef Name='Title' /><FieldRef Name='Assignee' /><FieldRef Name='Completed' /> </ViewFields> </viewFields>" +
                        "<rowLimit>99999</rowLimit>" +
                        "<queryOptions xmlns:SOAPSDK9='http://schemas.microsoft.com/sharepoint/soap/' > <QueryOptions/> </queryOptions>" + 
                    "</GetListItems>" +
                "</soap:Body> </soap:Envelope>";
    url: "/_vti_bin/lists.asmx",
    type: "POST",
    dataType: "xml",
    data: soapEnv,
    complete: CompleteListItem,
    contentType: "text/xml; charset=\"utf-8\""
function CompleteListItem(xData, status) {
    var itemId;
    var itemTitle;

    $(xData.responseXML).find("z\\:row").each(function () {
        itemId = $(this).attr("ows_ID");
        itemTitle = $(this).attr("ows_Title");
            operation: "UpdateListItems",
            aysnc: false,
            batchCmd: "Update",
            ID: itemId,
            listName: "myListName",
            valuepairs: [["Completed", "True"]],
            completefunc: function(xData, Status) {
                if (Status == 'success') {
                    var msg = "The assigned task '" + itemTitle + "' has been marked as complete.";
                    messageId = SP.UI.Notify.addNotification(msg, false);
                else {
                    alert(Status +' : There was a problem.');

As long as variable assignment and intial method call placed in proper checked event for checkbox, everything worked great.

| improve this answer | |
  • Wow, you weren't kidding about that not being pretty. – bgmCoder Nov 12 '15 at 3:47

Here is a link to a same question.

Taken from the link:

In the handler:

var id = $(this).closest('tr')[0].id;


var id = $(this).closest('tr').attr('id');

or if by "id" you meant its index, do this:

var id = $(this).closest('tr')[0].rowIndex;

Also try:

var id = obj.parentElement.nextSibling.innerText;
| improve this answer | |
  • This did not provide the info I needed. I am not displaying the ID in my data form web part. And a rowIndex property would not give me the list item ID that SharePoint itself uses. – JuanTrev May 17 '13 at 18:21
  • All lists have an ID, weather they are in DFWP or not. With the first two lines of code you can get the ID of the current row which you can use later as you want. – dzookatz May 20 '13 at 8:13

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.