Data Contection via web service to SharePoint Calendar - InfoPath Dev
in

InfoPath Dev

Data Contection via web service to SharePoint Calendar

Last post 07-30-2009 03:51 AM by cscott33. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 07-21-2009 05:38 AM

    Data Contection via web service to SharePoint Calendar

    Having problems with the following error message. My line in code that is failing is

    DataConnections("Web Service Submit").Execute()

    I have rechecked my Data Connection but I still get the following error:

     System.Net.WebExceptionInfoPath cannot submit the form.An error occurred while the form was being submitted.   at Microsoft.Office.InfoPath.Internal.MomExceptionHelper.ExecuteDataConnectionAction(OMCall d)   at Microsoft.Office.InfoPath.Internal.WebServiceConnectionHost.Execute()   at Template1.FormCode.CTRL11_5_Clicked(Object sender, ClickedEventArgs e) in H:\My Documents\InfoPath Projects\Template11\FormCode.vb:line 57   at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)   at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

    Can anyone make a suggestion as to the possible issue?

    Chris

  • 07-21-2009 08:47 AM In reply to

    Re: Data Contection via web service to SharePoint Calendar

    If you submit using InfoPath's built in functionality rather than in code, what happens? Is this a custom web service?

    Hilary Stoupa

  • 07-28-2009 08:25 AM In reply to

    Re: Data Contection via web service to SharePoint Calendar

    Hilary,

    I was able to figure this one out my batch (xml) prams were not set correctly. However I am trying to make the post to the calendar via a repeating table and that is proving a little bit more of a problem child.

    Chris 

  • 07-28-2009 09:05 AM In reply to

    Re: Data Contection via web service to SharePoint Calendar

    You are using the ShP UpdateListItems web service then? And an XML file for you CAML? You can add multiple Method nodes to your Batch element, so you can write some code to loop through your repeating group in your form and add a new Method node for each row you want to submit....

    Hilary Stoupa

  • 07-28-2009 10:54 AM In reply to

    Re: Data Contection via web service to SharePoint Calendar

    Yes, I am using both and was writing code behind to count rows and batch up and then execute the “Web Service Submit” However, I have a few bugs with the count of rows. I would be interested in understanding more about adding it to my xml file (batch) instead. Could you give me a little more insight on this?

  • 07-28-2009 12:03 PM In reply to

    Re: Data Contection via web service to SharePoint Calendar

    Which object model are you using? For 2003 code, you can use an IXMLDOMNodeList to loop through your nodes:

     //get the nodes
    IXMLDOMNodeList nodes = thisXDocument.DOM.selectNodes("/my:myFields/my:group1/my:group2");

    //loop through the nodes
    foreach (IXMLDOMNode node in nodes)
    {
         string value = node.text;
    }

    For 2007, use an XPathNodeIterator:

    //get the nodes           
    XPathNodeIterator nodes = MainDataSource.CreateNavigator().Select("/my:myFields/my:group1/my:group2", NamespaceManager);
     
    //loop through the nodes
    foreach (XPathNavigator node in nodes)
    {
         string value = node.Value;
    }

    In either scenario, you need to replace the XPath to match your data source. What are you using a row count for? What does your current code look like and where are the problems?

    Hilary Stoupa

  • 07-29-2009 06:05 AM In reply to

    Re: Data Contection via web service to SharePoint Calendar

    Thank you I will look and see how this can fit in. Here is what I have but the I either am trying to do this incorrectly or I am missing something.

    Dim root As XPathNavigator = MainDataSource.CreateNavigator()

    Dim title As String = root.SelectSingleNode("my:myFieldsReporting/AbsenceReportingSection/AbsenceSection/AbsenceReportingGroup/my:title", NamespaceManager).Value

    Dim location As String = root.SelectSingleNode("my:myFields/Reporting/AbsenceReportingSection/AbsenceSection/AbsenceReportingGroup/my:location", NamespaceManager).Value

    Dim startDate As String = root.SelectSingleNode("my:myFieldsReporting/AbsenceReportingSection/AbsenceSection/AbsenceReportingGroup/my:startDate", NamespaceManager).Value

    Dim startTime As String = root.SelectSingleNode("my:myFieldsReporting/AbsenceReportingSection/AbsenceSection/AbsenceReportingGroup/my:startTime", NamespaceManager).Value

    Dim endDate As String = root.SelectSingleNode("my:myFieldsReporting/AbsenceReportingSection/AbsenceSection/AbsenceReportingGroup/my:endDate", NamespaceManager).Value

    Dim endTime As String = root.SelectSingleNode("my:myFieldsReporting/AbsenceReportingSection/AbsenceSection/AbsenceReportingGroup/my:endTime", NamespaceManager).Value

    Dim secDSNav As XPathNavigator = DataSources("EventCAML").CreateNavigator()

    Dim iter As XPathNodeIterator = secDSNav.Select("/Batch/Method")

    Dim methodNodesCount As Integer = iter.Count

    Dim firstMethodNav As XPathNavigator = secDSNav.SelectSingleNode("/Batch/Method[1]", NamespaceManager)

    Dim lastMethodNav As XPathNavigator = secDSNav.SelectSingleNode("/Batch/Method[" & methodNodesCount.ToString() & "]", NamespaceManager)

    Dim batch As XPathNavigator = DataSources("EventCAML").CreateNavigator()

    Dim counter As Integer = 1

    Dim methodXml As XmlDocument = New XmlDocument()Dim batchNav As XPathNavigator = secDSNav.SelectSingleNode("/Batch", NamespaceManager)

    batchNav.AppendChild(methodXml.DocumentElement.CreateNavigator())

    Dim rows As DataSource

    While rows.MoveNext()

    counter = counter + 1

    batch.SelectSingleNode(
    "/Batch/Method/Field[@Name='Title']", _

    NamespaceManager).SetValue(title)

    batch.SelectSingleNode(
    "/Batch/Method/Field[@Name='Location']", _

    NamespaceManager).SetValue(location)

    batch.SelectSingleNode(
    "/Batch/Method/Field[@Name='EventDate']", _

    NamespaceManager).SetValue(String.Format("{0}T{1}Z", startDate, startTime))

    batch.SelectSingleNode("/Batch/Method/Field[@Name='EndDate']", _NamespaceManager).SetValue(String.Format("{0}T{1}Z", endDate, endTime))

     

    DataConnections("Web Service Submit").Execute()

    End While

  • 07-29-2009 12:00 PM In reply to

    Re: Data Contection via web service to SharePoint Calendar

    First, it looks like you are always selecting the first item from your repeating group. I'm going to guess that AbsenceReportingGroup is the node your repeating table is bound to. Your XPaths all look wrong -- I'd expect to see the 'my' namespace throughout.... Try this -- note, I changed the XPaths.

                Dim root As XPathNavigator = MainDataSource.CreateNavigator()
                Dim rows As XPathNodeIterator = root.Select("/my:myFieldsReporting/my:AbsenceReportingSection/my:AbsenceSection/my:AbsenceReportingGroup", NamespaceManager)
     
                'clone a method node
                Dim batch As XPathNavigator = DataSources("EventCAML").CreateNavigator().SelectSingleNode("/Batch", NamespaceManager)
                Dim method As XPathNavigator = batch.SelectSingleNode("Method").Clone()
     
                'delete all the existing method nodes
                Dim first As XPathNavigator = batch.SelectSingleNode("Method[1]", NamespaceManager)
                Dim last As XPathNavigator = batch.SelectSingleNode("Method[last()]", NamespaceManager)
     
                batch.MoveTo(first)
                batch.DeleteRange(last)
     
                'go through each row, clone our cloned node, set values and append
                Dim row As XPathNavigator
     
                For Each row In rows
     
                    Dim tempMethod As XPathNavigator = method.Clone()
     
                    Dim title As String = row.SelectSingleNode("my:title", NamespaceManager).Value
                    Dim location As String = row.SelectSingleNode("my:location", NamespaceManager).Value
                    Dim startDate As String = row.SelectSingleNode("my:startDate", NamespaceManager).Value
                    Dim startTime As String = row.SelectSingleNode("mmy:startTime", NamespaceManager).Value
                    Dim endDate As String = row.SelectSingleNode("my:endDate", NamespaceManager).Value
                    Dim endTime As String = row.SelectSingleNode("my:endTime", NamespaceManager).Value
     
                    tempMethod.SelectSingleNode("Field[@Name='Title']", NamespaceManager).SetValue(title)
                    tempMethod.SelectSingleNode("Field[@Name='Location']", NamespaceManager).SetValue(location)
                    tempMethod.SelectSingleNode("Field[@Name='EventDate']", NamespaceManager).SetValue(String.Format("{0}T{1}Z", startDate, startTime))
                    tempMethod.SelectSingleNode("Field[@Name='EndDate']", NamespaceManager).SetValue(String.Format("{0}T{1}Z", endDate, endTime))
     
                    batch.AppendChild(tempMethod)
     
                Next
     
                DataConnections("Web Service Submit").Execute()

    Another thing worth noting is I haven't tested this. It compiles, but may have an issue or two that need to be ironed out.

    Basically, I'm getting the rows from the repeating group. Then I create a clone of the 'method' node from the 'batch' xml. After that, I remove any existing method nodes in the batch file, so that I'm starting fresh. Then I'm getting values from a row, populating fields in the method node and appending the node to the batch. Finally, after all that is done, execute your web service connection to submit all at once.
    Hilary Stoupa

  • 07-30-2009 03:51 AM In reply to

    Re: Data Contection via web service to SharePoint Calendar

    Thanks I have been fighting this for about a week, I will compile and work on the bugs... this was the only item in all the code I put into this InfoPath I could not get my head around. Again thanks for the help and steering me in a different direction.

    Well this is giving me some interesting errors:

    System.Xml.XPath.XPathException
    XsltContext is needed for this query because of an unknown function.
       at MS.Internal.Xml.XPath.CompiledXpathExpr.UndefinedXsltContext.ResolveFunction(String prefix, String name, XPathResultType[] ArgTypes)
       at MS.Internal.Xml.XPath.FunctionQuery.SetXsltContext(XsltContext context)
       at MS.Internal.Xml.XPath.FilterQuery.SetXsltContext(XsltContext input)
       at MS.Internal.Xml.XPath.CompiledXpathExpr.SetContext(XmlNamespaceManager nsManager)
       at System.Xml.XPath.XPathExpression.Compile(String xpath, IXmlNamespaceResolver nsResolver)
       at System.Xml.XPath.XPathNavigator.SelectSingleNode(String xpath, IXmlNamespaceResolver resolver)
       at Time_Cards.FormCode.CTRL53_5_Clicked(Object sender, ClickedEventArgs e) in H:\My Documents\InfoPath Projects\Time Cards1\FormCode.vb:line 62
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

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