Using VB to update a SharePoint 2007 list item in InfoPath 2003 - InfoPath Dev
in

InfoPath Dev

Using VB to update a SharePoint 2007 list item in InfoPath 2003

Last post 12-13-2011 09:16 AM by Daggy. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 12-08-2011 07:04 AM

    • Daggy
    • Not Ranked
    • Joined on 12-08-2011
    • Posts 2

    Using VB to update a SharePoint 2007 list item in InfoPath 2003

     Hello,

     For the past few days I have been trying to set up an IP 2003 form to update a specific item in a SP 2007 list.

    The list has the following: Title, Year, Month, TicketCount, TicketsCompleted

     The following is in my caml.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
    <Batch OnError="Continue">
        <Method ID="1" Cmd="Update">
            <Field Name='Title'></Field>
            <Field Name="Year"></Field>
            <Field Name="Month"></Field>
            <Field Name="TicketCount"></Field>
            <Field Name="TicketsCompleted"></Field>
        </Method>
    </Batch>

    With VB I managed to find and use some code to retrieve a row's information, however I was not able to get it to iterate through all rows. (i.e. I was only able to retrieve the first row's data... when trying to access any other rows it would just return the first row's information).

    More importantly I have not yet been able to figure out how to update the secondary data source's XML file and then send it back to the SP 2007 list to update the row. I was able to create an entirely new row, however updating an existing row has seemed impossible.

     What I need help with, I think, is reading/updating the secondary data source's .xml file and then submitting it to the SP 2007 list to update it.

     I have been using google relentlessly for answers... almost all related links pop up purple/read and I still haven't managed to create a solution.

     Any help/guidance would be greatly appreciated.

     

  • 12-13-2011 09:16 AM In reply to

    • Daggy
    • Not Ranked
    • Joined on 12-08-2011
    • Posts 2

    Re: Using VB to update a SharePoint 2007 list item in InfoPath 2003

     Still struggling with this... some more information

    http://blog-sharepoint.blogspot.com/2009/07/summary-how-to-programmatically-update.html

    http://blog-sharepoint.blogspot.com/2009/07/infopath-update-repeating-elementsnodes.html

    I've followed through the guides and comments within the guides listed above. The most helpful part was the comments. I was able to follow them through to the end, however the desired functionality isn't achieved... 

     

    Here's the code that I use:

     'Load the XML Document of the repeating data source
    Dim xmlDataSource
    Dim UpdateXML
    Set xmlDataSource = XDocument.GetDOM("camlstats")
    Set UpdateXML = xmlDataSource.selectNodes("/Batch/Method/Field")

    'This loops through the repepeating element in the data source and
    'sets the value of the repeating field if the name attribute matches
    'the first param: XMLFieldName.  
    'the sourceField param accepts a string containing the XPath to the
    'field which has the value which is to be set as
    'the value of the required repeating element.
    Sub updateXMLDataSource(XMLFieldName, sourceField)
      Dim count
      Dim DSNode

      'Loop through each element in the data source to find the
      'required field in the CAML template

      For count = 0 To UpdateXML.length -1
        'Test if the name attribute of the current
        'element matches the required field
        If UpdateXML(count).getAttribute("Name") = XMLFieldName Then
          'Element Found: Update the value of current
          'element to the value of souceField parameter (XPATH)
            Set DSNode = XDocument.DOM.selectSingleNode(sourceField)
            UpdateXML(count).text = DSNode.text
          End If
      Next
     
    End Sub

    Sub XDocument_OnLoad(eventObj)
    ' Write your code here
    End Sub

    '=======
    ' The following function handler is created by Microsoft Office InfoPath.
    ' Do not modify the name of the function, or the name and number of arguments.
    '=======
    Sub CTRL16_5_OnClick(eventObj)
        dim MyField

        For count = 0 To UpdateXML.length -1
            MyField = UpdateXML(count).getAttribute("Name")
            Msgbox MyField
            MsgBox UpdateXML(count).text
        Next
        Dim Items
        Set SharePointDataSource = XDocument.GetDOM("Network Access Form Statistics-viewonly")
        SharePointDataSource.setProperty "SelectionNamespaces", "xmlns:dfs=""http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"""
        Set Items = SharePointDataSource.selectNodes("/dfs:myFields/dfs:dataFields/dfs:Network_Access_Form_Statistics")

        MsgBox Items.Length 'returns correct number -- 2

        For count = 0 to Items.Length - 1
            MsgBox Items(count).selectSingleNode("//@Title").Text 'returns the first title twice, but not second
        Next
        Call updateXMLDataSource("Year", "/my:myFields/my:updatetext")
    End Sub

    '=======
    ' The following function handler is created by Microsoft Office InfoPath.
    ' Do not modify the name of the function, or the name and number of arguments.
    '=======
    Sub CTRL18_5_OnClick(eventObj)
        XDocument.DataAdapters("Store Lists on SP").Submit
    End Sub



    =======================================================================

    This loop:

     For count = 0 To UpdateXML.length -1
            MyField = UpdateXML(count).getAttribute("Name")
            Msgbox MyField
            MsgBox UpdateXML(count).text
        Next

    The first MsgBox successfully displays the column names noted in the caml.xml above. 

    The second MsgBox displays nothing.

     =======================================================================

    This loop:


        For count = 0 to Items.Length - 1
            MsgBox Items(count).selectSingleNode("//@Title").Text 'returns the first title twice, but not second
        Next

     
    Displays the first row's "Title" data for however many total rows there are, however it does not successfully display each row's title data, only the first.

     =======================================================================

     

    I'm going to continue using Google to search how to update a SP 2007 list via IP 2003 using VB. If anyone has successfully been able to do this I would greatly appreciate some guidance!

     

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.