Retrieving the id of an inserted item using sp services

I was working on a project the other day and needed to get the id of an inserted item into a SharePoint 2007 custom list.  I was not even sure if it was possible and if there was any sample code out there.  With faith and my good friend beside me, Google, I began my search.  I searched everywhere and finally came to this helpful site  http://www.bjw.co.nz/developer/sharepoint-2010/1173-returning-the-new-id-with-spservices-updatelistitems

Here’s how I used the code:

function getID(measureID,FY)
 {
     var newItemID = null;
    $().SPServices({
     operation: "UpdateListItems",
     listName: "Results List",
     batchCmd: "New",
     async: false,
     valuepairs: [
       ["Title", measureID],
       ["FiscalYear", FY]
],
    completefunc: function(xData, Status) {
           var newId = $(xData.responseXML).SPFilterNode("z:row").attr("ows_ID");
            newItemID = newId;
    } 
  });
  return newItemID; 
 }

Hopefully, this blog post can narrow the search on this topic. 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s