Using CAML to update a sharepoint list... oh, my, god... - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Using CAML to update a sharepoint list... oh, my, god...

Last post 08-05-2016 11:13 AM by EliLawson. 30 replies.
Page 2 of 3 (31 items) < Previous 1 2 3 Next >
Sort Posts: Previous Next
  • 07-22-2015 09:21 AM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

    I'm trying to understand which part of this tells it which record or records to update in the list?  I know the data connection has the List ID.  The only unique ID I have in my list right now is a URL (Single Line) field. 

  • 07-22-2015 09:29 AM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

     For updates, your CAML needs to include the SharePoint List Item ID for the item. So, if you add the ID column to your view in SharePoint, you can see that.... if you have a data connection to your list in InfoPath you can include this ID column as well.

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

    The sample code found here shows nice CAML batch for updates: https://msdn.microsoft.com/en-us/library/office/ms440289(v=office.14).aspx 

    Hilary Stoupa

  • 07-22-2015 10:12 AM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

    So the only way to update it is by the SharePoint List Item ID? Is it possible then for example, to update the status field of all 3 items below to be cancelled? Keep in mind I cannot use code. 

     ID      Name    Status      URL

    1         Bob      Active      www.url.com/travel1

    2         John      Active    www.url.com/travel1

    3      Sara         Active     www.url.com/travel1

    TIA

  • 07-22-2015 10:19 AM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

     The only way to update is by using the SharePoint List Item ID. I figured based on the title of your post you were already using CAML and the UpdateListItems web service? There are lots of posts on here about doing this. This thread is a pretty good one: http://www.infopathdev.com/forums/t/26246.aspx?PageIndex=1

    Hilary Stoupa

  • 07-22-2015 10:30 AM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

    Hilary, Yes I am using CAML and the UpdateListItems web service.  I meant I can't use anything that would require Visual Studio since I don't have access to that. 

    Funny you should provide that link! The list that I'm updated is created using the link that you sent.  So I have the Form library with the form with a repeating table of individual travelers, and then they get sent to another list by individual. And I'm trying to have it update the corresponding fields when they do a cancel in the Form. But right now the only thing connecting the two in my list is that URL that ties it back to the travel form.

  • 07-22-2015 10:44 AM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

     The reason I posted a link to a code sample is that it has a nice sample CAML batch in the code - simply meant to show you the correct CAML syntax. If you include the proper method and the <Field Name="ID">YOURIDNUMBERHERE</Field> in your CAML batch, and submit that CAML to the UpdateListItems web service (along with whatever data you want to update), the submit should update your list items. You'll see the correct syntax for a CAML delete also in that code sample: <Method ID='1' Cmd='Delete'><Field Name='ID'>5</Field></Method>.

    Oh, sorry, I think I get what you are saying now.  You don't have the IDs for the items.... We can't query on a URL from a regular list data connection either, or I'd suggest adding a connection to a list, and querying for just the items that match the URL. Have you thought about adding another column you could use as an identifier that you could query on? Just call it "form ID" or something and make it a single line of text, have a field in your form that you set to a unique value (username + now() or some thing) the first time it is opened, and then when you need to get the IDs back for your items, you'd have a key you could use?

    Hilary Stoupa

  • 07-22-2015 10:55 AM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

    Hmm, regarding your identifier column, I thought that was what I was doing by having the URL field. It is of field type "Single Line of Text".   I guess I could simply it to just the form name? Or maybe I'm jsut not understanding what your suggestion.

    Again, thank you in advance for your assistance!

  • 07-22-2015 11:03 AM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

     Okay. You had said the column was a URL. :) I thought you meant the column type was a hyperlink.

    You should be able to:

    1. Add a data connection to the list you are submitting data to
    2. Include the URL column and the ID column in the data connection
    3. Don't query for data on load
    4. In the form, set the query URL field in the new data connection to the form URL
    5. Query the data connection

    This should return just the rows where the URL matches and that should allow you to get the IDs. Does that make sense? You are using InfoPath 2010 or 2013, I hope - list data connection query fields don't exist in 2007.... 

    Hilary Stoupa

  • 07-22-2015 11:16 AM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

    Hilary, sorry about the misunderstanding with the URL!  And yes, I'm using Infopath 2013 thank goodness!

    I created the data connection, but I'm not sure what you mean for Step 4? And then once I have the IDs in that data connection, I'm not sure how I would pass them to the webservice connection?

  • 07-22-2015 11:23 AM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

     In your new data connection, you should see query fields and data fields. You can set a query field in the list to a value (in this case it will be this URL value that you submitted to the list originally) and then query for data - here's a blog post with some info: http://wonderlaura.com/2011/8/1/infopath-query-specific-sharepoint-list-data/

    You'll have to add some form logic to update your CAML with the ID for each of the returned rows.... maybe include some fields you can repurpose in you data connection to the list, like Created and Created By, and repurpose those for updating and submitting your CAML....

    Like - you could execute the query that gets back the IDs, and then set Created in that data source to blank (which would change all instances of Created) and have a rule on Created that if it is blank, go set the ID and status in the CAML batch and submit it.... 

    Hilary Stoupa

  • 07-22-2015 02:01 PM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

    Hilary thank you for your patience! This is quickly stretching my InfoPath skills. I will take a closer look at this and see if I can make something work. I may be back with questions. :)
  • 12-17-2015 09:26 AM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

     Hilary, Thank your help. I know this was several months ago, but finally I got around to troubleshooting and was able to get the updating to work. I did have to use the ID instead of the URL. 

    I wanted to see if there were any suggestions on how to delete a record if they delete it from the repeating table? Since the record is deleted, I'm not sure how to grab the ID.

  • 12-17-2015 02:06 PM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

    Deleting is going to be hard, for the exact reason you mention - how do you know what was deleted? I'd probably add a "delete" button to my table and teach users to use that instead. Add a column named "Removed" to your list, add a hidden field called removed to your form. Hide rows in the form table where Removed = true, and then, on the delete button in the form, set removed to true. That way you can hide stuff in the list / form that the user wants to delete.
    Hilary Stoupa

  • 03-17-2016 10:38 AM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

     Hi Hilary,

    Thanks for referencing my post.  I've just migrated my blog, so the URL has changed: http://wonderlaura.com/2011/8/1/infopath-query-specific-sharepoint-list-data 

  • 03-17-2016 10:45 AM In reply to

    Re: Using CAML to update a sharepoint list... oh, my, god...

     Thanks for letting me know! I also updated the URL in my mention above in case someone doesn't read down all the way. :)

    Hilary Stoupa

Page 2 of 3 (31 items) < Previous 1 2 3 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.