Programmatically Copy Date Field From Secondary Connection Reapeating Table into Date Field within Main Connection Reapting Table - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Programmatically Copy Date Field From Secondary Connection Reapeating Table into Date Field within Main Connection Reapting Table

Last post 04-29-2013 07:45 AM by Hilary Stoupa. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 04-28-2013 08:11 AM

    Programmatically Copy Date Field From Secondary Connection Reapeating Table into Date Field within Main Connection Reapting Table

    Hi, I currently have an IP2010 Library Form that populates a repeating table from a secondary connection (table that is left of the solid black line).  Within that secondary connection, I've created a button on each row of the repeating table the the user can click and it will populate a new row within a repeating table on my Main Data Connection (to the right of the solid black line).  I have not problem getting the text fields to copy over, but I am running into some trouble when trying to copy the date field from the secondary connection into the date field on the main connection.

    Here is the code as it stands now:

                XPathNavigator nav = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:dataFields/my:repeatingGroup[last()]", NamespaceManager);
                XPathNavigator row = nav.Clone();
                row.InsertAfter(nav);
                AddValue(e.Source, row, "d:Title", "my:EventName");
                AddValue(e.Source, row, "d:Event_x0020_Type", "my:EventType");
                AddValue(e.Source, row, "d:Event_x0020_Location", "my:EventLocation");
                AddValue(e.Source, row, "d:Planned_x0020_Start", "my:CurrentPlannedStartDate"); <----(This is the line I'm running into trouble with)
            }
            private void AddValue(XPathNavigator source, XPathNavigator target, string sourcePath, string targetPath)
            {
                target.SelectSingleNode(targetPath, NamespaceManager).SetValue(source.SelectSingleNode(sourcePath, NamespaceManager).Value);
            }
    I'm still new to coding and working my way through as I go, so any help would be appreciated.
  • 04-28-2013 11:28 AM In reply to

    Re: Programmatically Copy Date Field From Secondary Connection Reapeating Table into Date Field within Main Connection Reapting Table

    Hi Jim Shorts,

    Well, you certainly don't need code for this. Date fields have an xsi:nil attribute that needs to be set correctly (or removed). That's probably why you're having trouble. Why not just use rules to do this? Then, you don't have to worry about the attributes.

    Here's a link to a sample that shows how to copy with rules: http://www.infopathdev.com/blogs/patrick/archive/2011/09/03/free-sample-copying-repeating-data.aspx

    Good luck!

    Patrick Halstead
    Project Manager at Qdabra
  • 04-28-2013 12:27 PM In reply to

    Re: Programmatically Copy Date Field From Secondary Connection Reapeating Table into Date Field within Main Connection Reapting Table

    Thank you for the response, Patrick.  I do appreciate the input.  However, there are quite a few other things that are going on with this form that I haven't shown in this example which lead me to have to do a fully coded solution.  I really like your example and wish I would have found it sooner as it would have saved me about a weeks worth of headaches trying to complete this part using just rules.  However, even if I would have gone the rules route, I still would have the same question with your example as I have with my coded solution: How would I go about copying a date field from a secondary query data connection into a date field within my main connection?  As of right now, I can copy over the date field from my secondary connection into a single line of text field on my main connection, but i get this output: 2012-01-30T00:00:00.  Any ideas for converting that to a format of MM/DD/YYYY?  Thanks again!

  • 04-28-2013 04:16 PM In reply to

    Re: Programmatically Copy Date Field From Secondary Connection Reapeating Table into Date Field within Main Connection Reapting Table

    The date string you have is a valid date / time for XML - so you could just format the control to display this the way you want to see it (MM/DD/YYYY).

    Hilary Stoupa

  • 04-28-2013 06:18 PM In reply to

    Re: Programmatically Copy Date Field From Secondary Connection Reapeating Table into Date Field within Main Connection Reapting Table

    Hi Hilary, and thank you very much for your response.  Currently, the main data connection field is set as a single line of text field.  When I right click on the field and go into the text box properties screen, I see that I am able to set this field as a Data Type: Date and then go in and format according to my needs.  However, once I do this (even when I select the Date and Time data type), I continually get an error once the data is passed from my secondary connection to my main connection:

     "System.InvalidOperationException
    Schema validation found non-data type errors.
       at Microsoft.MsoOffice.InfoPath.MsxmlInterop.MsxmlDocument.ThrowExceptionFromMsxmlInteropError(MsxmlInteropError eError)
       at Microsoft.MsoOffice.InfoPath.MsxmlInterop.MsxmlDocument.ThrowExceptionFromHresult(Int32 hrError)
       at Microsoft.MsoOffice.InfoPath.MsxmlInterop.MsxmlNodeImpl.set_Text(String strText)
       at Microsoft.Office.InfoPath.MsxmlNavigator.SetValue(String value)
       at Date_Change_Test_Library_Form_Template.FormCode.AddValue(XPathNavigator source, XPathNavigator target, String sourcePath, String targetPath)
       at Date_Change_Test_Library_Form_Template.FormCode.AddRow(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)"

     Perhaps you're talking of another way that I can format the control to display the way I'm wanting to see it?

  • 04-29-2013 07:45 AM In reply to

    Re: Programmatically Copy Date Field From Secondary Connection Reapeating Table into Date Field within Main Connection Reapting Table

    Do you need for users to be able to change this data? If not, you can use an expression box (calculated value) and even leaving the data type as string, display as date formatted. If it is a date data type, you'll need to remove the nil attribute prior to setting the value. Search this article for nil to find the section on how to do that programmatically.

     

    Hilary Stoupa

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