Get ID when creating item with lists.asmx

  • 7 November 2017
  • 3 replies
  • 44 views

Badge +3

Hello,

when using the "create item"-action I have the option the get the ID of the element that I am creating. This allows me to set a "set item permission" on exactly this element that I created.

I need to use the web service "lists.asmx" to create the item, but I don't know if there is a way to get the ID of the created element.

Can you help?


3 replies

Userlevel 5
Badge +8

Hi Christian,

When you create a new list item using the UpdateListItems method, the response content should contain the XML node for the updated rows (including the item ID).  You should be able parse out the ID out from that response content using a query XML action and/or a Regular Expression action.

This MSDN article should provide more context for what is returned.

Badge +3

Thanks Dan,

if I had put in a little bit more effort I would have found it.

So now I am starting the web service "lists.asmx" with the following code:

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:m="http://schemas.microsoft.com/sharepoint/soap/">

  <soap:Header>

  </soap:Header>

  <soap:Body>

    <m:UpdateListItems>

      <m:listName>listname</m:listName>

      <m:updates>

  <Batch RootFolder="/sites/SiteCollectionName/listname/parentfolder/childfolder">

   <Method ID="1" Cmd="New">

    <Field Name="ID">New</Field>

    <Field Name="FSObjType">1</Field>

    <Field Name="BaseName">namefornewchildfolder</Field>

   </Method>

  </Batch>

      </m:updates>

    </m:UpdateListItems>

  </soap:Body>

</soap:Envelope>

Then I am using the Query-XML-action to get the ID with "//z:row/ows_ID".

That will give me the correct ID.

Thanks a lot

Badge +11

The XPath Expression should rather be "//z:row/@ows_ID" as this is the syntax to get the value of the "ows_ID" attribute. Select "inner Text" in xml query action.

Reply