Oops I'm A Geek

Wednesday, November 08, 2006

How to update SharePoint V2 lists from InfoPath 2003

I wanted to put this piece - contributed by Yonah Wolf - on my blog so as not to lose it. It is the vital piece to using InfoPath data fields to update a CAML file which in turn updates the SP list

What you are doing here is using the CAML as a template to create a record, which you then post to SharePoint's web service to add a new item.


Matt's example
, binds the UI to the CAML so that as you update data in the UI, you are, in effect, modifying the CAML. To get this to work in the pretty version, all you need to do is write a script that inserts the data from your formfields into the CAML.

Here is how I did it:

1. I set up the Data Connections (to both the CAML and to SharePoint) as described in Matt's Article

2. I laid-out my form in the 'Pretty' format.

3. For each of my form fields, I assigned the same name as the corresponding field in the CAML - for example, if the field name is 'FirstName' in CAML, my form field was called 'FirstName'

4. I changed the submit action to call a script.
5. Using the script editor, I entered this code in the onSubmit method:



caml1 is my CAML file and SharePoint is my submit data source. Essentially what this code does is it gets the list of fields from the CAML, and then loops through them and attempts to set the CAML value to the form field with the same name. When the mapping is done, it posts to SharePoint.

PLEASE NOTE: The only way that this will work is if the CAML field and the Corresponding form field have the exact same name.

0 Comments:

Post a Comment

<< Home