Reading / Editing / Writing SharePoint List Items In InfoPath Possible? - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Reading / Editing / Writing SharePoint List Items In InfoPath Possible?

Last post 11-28-2007 03:02 AM by Shiraz Cupala. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 10-02-2007 11:24 AM

    Reading / Editing / Writing SharePoint List Items In InfoPath Possible?

    I need some help.  I have been trying to figure out a way to edit SharePoint list Items in InfoPath 2003.  I can successfully create list items no problem using web services, and can read them using data connections.  I am trying to find a way to update or rewrite the list items I am pulling down.  Here's my problem.  I have a list  that I want to pull info infopath, allow the user to check yes or no (checkbox is fine) for each list item.  This yes/no should not exist in the original list but only in the form.  My goal is to then write the records into a different list, including the checkbox value.  I have read everything I can find but I can't seem to find a solution to the middle part of this problem. So here's an example.  Basically, I want to append a field to each list item and push it into another list.  Keep in mind I know how to pull the data, and write the data, the middle part is what I can't figure out.  Specifically, how to read the non-persistent values out of a table based on a secondary data source, how to add a column that can be read with the retrieved list items in the repeating table.  I don't care about persistence in the form.  Just pulling the list items, adding a column of data, and writing them to another list.  PLEASE if you have any ideas help me as I am completely stuck.

    List 1                                   Form                                                 List 2

    SharePoint List          --->      Repeating Table                        ---->   SharePoint List  

    Col A, Col B, Col C                Col A, Col B, Col C, [No/Yes]             Col A, Col B, Col C, Col D (Yes No selected in form)
     

    -Justin Devine
    Consultant
  • 10-02-2007 02:30 PM In reply to

    Re: Reading / Editing / Writing SharePoint List Items In InfoPath Possible?

    There are numerous articles about this topic. I for one struggled for a while with this. My solution uses the same web services however when you build your xml you use Update for the Cmd instead of New. Another thing you have to grab is the record ID of the list item you want to update. You'll need a key to link the two list and then you'll have to loop through your repeating data (if it's repeating) to assign the key to a hidden field, then you grab it on submit. Here is one such block of code I am using. Hope it helps.

     Sub PublishToOrderTable()
                Dim i As Integer
                Dim iRows As Integer = thisXDocument.DOM.selectNodes("//my:myFields/my:OrderDetail").length

                Dim orders As New WS_BGB.Lists
                Dim cr As New System.Net.NetworkCredential("username", "password", "domain")
                orders.Credentials = cr

                Dim doc As New XmlDocument
                Dim updates As XmlElement = doc.CreateElement("Batch")

                '********************************************
                'Non repeating data pushsed to data table

                Dim OrderSource As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderSource").text
                Dim OrderNumber As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderNumber").text
                Dim DateofOrder As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:DateofOrder").text
                Dim DateFulfilled As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:DateFulfilled").text
                'Dim TotalCost As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:TotalCost").text
                Dim FormName As String = thisXDocument.DOM.selectSingleNode("/my:myFields/my:FormName").text
                Dim CustomerName As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:Customer/my:CustomerName").text
                Dim CustomerRecordId As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:Customer/my:CustomerRecordId").text
                Dim CustomerNumber As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:Customer/my:CustomerNumber").text
                Dim OrderFormNumber As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderFormNumber").text
                'Dim SortStatus As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:SortStatus").text

                '********************************************

                For i = 1 To iRows
                    '******************************************
                    'Repeating data

                    Dim boxNum As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:BoxNumber").text
                    Dim product As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:ProductOrderD").text
                    Dim ARSTrackingNum As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:ARSTrackingNumber").text
                    Dim postalTrackingNumber As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:PostalTrackingNumberD").text
                    Dim fulfilled As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:Fulfilled").text
                    'Dim Cost As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:CostPerUnitD").text
                    'Dim CostAdjustment As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:CostAdjustmentD").text
                    Dim ShipMethod As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:MethodofShippingD").text
                    Dim OrderDetailId As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:OrderDetailID").text
                    Dim receivedDate As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:ReceivedDate").text
                    Dim sortingDate As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:SortDetail[1]/my:SortingDate").text
                    'Dim sortingDate As String = ""
                    Dim grossWeight As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:GrossWeight").text
                    'Dim batteryChemistry As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:BatteryChemistry").text
                    Dim batteryChemistry As String = ""
                    'Dim sortedBy As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:SortedBy").text
                    Dim sortedBy As String = ""
                    Dim boxActive As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:BoxActive").text
                    'Dim TrackingContainer As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:TrackingContainer").text
                    Dim TrackingContainer As String = ""
                    Dim BoxReturnNumber As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:OrderDetail[" & i & "]/my:BoxReturnNumber").text
                    Dim ReturnFacility As String = thisXDocument.DOM.selectSingleNode("//my:myFields/my:ReturnFacility").text

                    '******************************************

                    '******************************************
                    'Build XML document to pass to the web service. First determine if it's a new submission or an update
                    '
                    '
                    '******************************************
                    If OrderDetailId = "" Then
                        updates.InnerXml = "<Method ID='1' Cmd='New'><Field Name='OrderSource'>" + OrderSource + "</Field><Field Name='OrderNumber'>" + OrderNumber + _
                        "</Field><Field Name='DateofOrder'>" + DateofOrder + "</Field><Field Name='DateFulfilled'>" + DateFulfilled + _
                        "</Field><Field Name='CustomerNumber'>" + CustomerNumber + _
                        "</Field><Field Name='ProductOrdered'>" + product + _
                        "</Field><Field Name='ShippingMethod'>" + ShipMethod + _
                        "</Field><Field Name='PostalTrackingNumber'>" + postalTrackingNumber + "</Field><Field Name='BoxNumber'>" + boxNum + _
                        "</Field><Field Name='ARSTrackingNumber'>" + ARSTrackingNum + "</Field><Field Name='Fulfilled'>" + fulfilled + _
                        "</Field><Field Name='ReceivedDate'>" + receivedDate + "</Field><Field Name='SortedDate'>" + sortingDate + "</Field><Field Name='BatteryChemistry'>" + batteryChemistry + _
                        "</Field><Field Name='GrossWeight'>" + grossWeight + "</Field><Field Name='SortedBy'>" + sortedBy + "</Field><Field Name='Cancelled'>" + boxActive + "</Field>" + _
                        "<Field Name='FormName'>" + FormName + "</Field><Field Name='CustomerName'>" + CustomerName + "</Field><Field Name='CustomerRecordId'>" + CustomerRecordId + "</Field>" + _
                        "<Field Name='OrderFormNumber'>" + OrderFormNumber + "</Field><Field Name='TrackingContainer'>" + TrackingContainer + "</Field>" + _
                        "<Field Name='ReturnShippingNumber'>" + BoxReturnNumber + "</Field><Field Name='ReturnFacility'>" + ReturnFacility + "</Field></Method>"
                   

                        ElseIf OrderDetailId <> "" Then
                        updates.InnerXml = "<Method ID='1' Cmd='Update'><Field Name='OrderSource'>" + OrderSource + "</Field><Field Name='OrderNumber'>" + OrderNumber + _
                        "</Field><Field Name='DateofOrder'>" + DateofOrder + "</Field><Field Name='DateFulfilled'>" + DateFulfilled + _
                        "</Field><Field Name='CustomerNumber'>" + CustomerNumber + _
                        "</Field><Field Name='ProductOrdered'>" + product + _
                        "</Field><Field Name='ShippingMethod'>" + ShipMethod + _
                        "</Field><Field Name='PostalTrackingNumber'>" + postalTrackingNumber + "</Field><Field Name='BoxNumber'>" + boxNum + _
                        "</Field><Field Name='ARSTrackingNumber'>" + ARSTrackingNum + "</Field><Field Name='Fulfilled'>" + fulfilled + _
                        "</Field><Field Name='ReceivedDate'>" + receivedDate + "</Field><Field Name='SortedDate'>" + sortingDate + "</Field><Field Name='BatteryChemistry'>" + batteryChemistry + _
                        "</Field><Field Name='GrossWeight'>" + grossWeight + "</Field><Field Name='SortedBy'>" + sortedBy + "</Field><Field Name='ID'>" + OrderDetailId + _
                        "</Field><Field Name='Cancelled'>" + boxActive + "</Field><Field Name='FormName'>" + FormName + "</Field><Field Name='CustomerName'>" + CustomerName + "</Field>" + _
                        "<Field Name='CustomerRecordId'>" + CustomerRecordId + "</Field><Field Name='OrderFormNumber'>" + OrderFormNumber + "</Field><Field Name='TrackingContainer'>" + TrackingContainer + _
                        "</Field><Field Name='ReturnShippingNumber'>" + BoxReturnNumber + "</Field><Field Name='ReturnFacility'>" + ReturnFacility + "</Field></Method>"
                    End If

                    orders.UpdateListItems("{0A82E0E5-A558-48A6-BA4C-46DE27D3B9FC}", updates)
                Next

            End Sub

     

    Shaun Nieves
    Sharepoint Manager
  • 10-03-2007 02:00 AM In reply to

    Re: Reading / Editing / Writing SharePoint List Items In InfoPath Possible?

    Hello

    Please read this Howto on Update list Items using Infopath

    http://archive.infopathdev.com/howto/tutorials/default.aspx?i=7bc880f391b84ea9b3b45c6fbecc07c6

    I hope this will help you

    Kalyan G Reddy
    Infopath MVP 2007 and 2008
  • 10-03-2007 06:20 AM In reply to

    Re: Reading / Editing / Writing SharePoint List Items In InfoPath Possible?

    Thanks for your help.  My real issue, however is in adding the column of data.  I can't seem to add a column to a repeating table bound to a secondary data source.  I keep getting the can't bind a non repeating element to a repeating... error  This column/field does not exist in list one only in list two.  So my goal is to populate a repeating table with the content of one sharepoint list, tack on a column, and write the complete rows to a new list.  I am very familiar with the web services, its targeting the data I want, including the new field, that is giving me fits.
    -Justin Devine
    Consultant
  • 10-03-2007 10:14 AM In reply to

    Re: Reading / Editing / Writing SharePoint List Items In InfoPath Possible?

    Now that's a tough one. The only thing I can think of is to manually fill the contents of your secondary data connection into a repeating table that includes your new field and update the second list by iterating through your filled table. Not that elegant but should accomplish what you are trying to do.

    Shaun Nieves
    Sharepoint Manager
  • 11-21-2007 09:31 AM In reply to

    Re: Reading / Editing / Writing SharePoint List Items In InfoPath Possible?

    Just wondering if you figured out how to do this because I'm looking to do something similiar.

    I have a repeating table on my form that is based on a secondary data source (SharePoint list).  I have set one of the fields to be editable (i.e. everything else is read only) in order to allow the user to update this field.  At the bottom of the table, there's an Update button which will update the secondary data source based on whatever changes the user made.  In the name of efficiency (and accuracy), I only want to update the rows that the user changes and I want to update them all at once (i.e. when the user clicks the Update button.)

    My original thought was to tack on a hidden column to the repeating table that is not part of the secondary data source.  Basically, this column would be initially set to false for each row and I'd change it to true for each row that the user updates (onAfterChange event for the field that's editable).  So when the user clicks the Update button, I know which rows need to be updated in the secondary data source and I can loop through and update the appropriate ones.

    I'm certainly open to other ideas on how to do this if someone has another suggestion.

  • 11-21-2007 02:53 PM In reply to

    Re: Reading / Editing / Writing SharePoint List Items In InfoPath Possible?

    I came up with a solution to my own problem and thought I'd provide an update for others.

    Since I couldn't figure out how to tack on a hidden column, I decided to use a good ol' fashioned global array to keep track of things.  Basically, any time the field is edited (onAfterChange), I add the ID to the global array.  When the user clicks the Update button, I just loop through the arrary.

    Very simple.  :)

  • 11-27-2007 07:24 AM In reply to

    Re: Reading / Editing / Writing SharePoint List Items In InfoPath Possible?

    My solution was different than yours FYI.  My solution was to create a Primary Data Source from an XML file that mirrors the list structure, then populate that structure with list items, and then its fully editable and you just write it back.  I plan to do a blog about this sometime soon, stay tuned.

     

    -Justin 

    -Justin Devine
    Consultant
  • 11-27-2007 10:45 PM In reply to

    Re: Reading / Editing / Writing SharePoint List Items In InfoPath Possible?

    It's a coincidence but we are working on a project right now that writes SharePoint list items based on fields in an InfoPath form. I'll ask Shiraz to chime in.

    Patrick Halstead
    Project Manager at Qdabra
  • 11-28-2007 03:02 AM In reply to

    Re: Reading / Editing / Writing SharePoint List Items In InfoPath Possible?

    There are a number of interesting InfoPath to WSS List scenarios in this thread. Right now we are working on a tool to one-way "migrate" or "import" data in InfoPath XML files to a SharePoint list. The scenario is that you have two independent processes: one is an IP form and another is a WSS List. The tool would allow you to take the IP forms, define a mapping between XPaths in the XML and columns in the WSS List. Then you feed in XML files and it creates a list item for each and populates the mapped data.

    Short term this would be just one-way so updates in the list wouldn't get to the IP forms and reimporting the IP form would create a new list item. This mainly due to trying to be generic, and do have two-way there needs to be a unique identifier in each form which may not exist for all forms. But you could imagine adding that in.

    A question for the group is how much value to you is there in this kind of mapping and automating the one-way migration/import vs. needing two-way linking.

     

     

    Shiraz Cupala / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 1 (10 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.