Copy text from one repeating table to another - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Copy text from one repeating table to another

Last post 07-29-2011 07:36 AM by ChuckP. 49 replies.
Page 2 of 4 (50 items) < Previous 1 2 3 4 Next >
Sort Posts: Previous Next
  • 02-26-2008 05:00 AM In reply to

    Re: Copy text from one repeating table to another

    OH my, steeeeeeeeeep learning curve.

    It was well after 01.00 AM when i gave up and went to sleep on it... and the answer was just in front of me. Spelling ...

    That Microsoft Script Editor is too basic to be good as it doesn't check on spelling (or has Intellisense in it) ... or they just did it like this to filter the real GOOD guys from the others that are just fiddling to get it to work. Like me

    Syntax, Syntax, Syntax..

     

    I got it to work now. I promise to get my code up here with a couple of screenshots for others like me that had a hardtime to sort it out- specially with Oracle webservices..

    tnxs a million

    K

    KriZ
  • 02-28-2008 04:25 AM In reply to

    Re: Copy text from one repeating table to another

    I am trying to create a infopath form that will copy some of the data entered in the first row of a repeating table into the next row. This will copy when the user presses a button to add another row in the table. I am trying to use jScript to do this and I am having lots of trouble. The datasource I am working with is:

    myFields

       - table

           -- name

           -- task

    The code I have so far is:

     

    function CTRL26_5::OnClick(eventObj)

    {

    // Write your code here

    var tempName = eventObj.Source.selectSingleNode("/my:myFields/my:table/my:name").text;

    var row = XDocument.DOM.selectSingleNode("/my:myFields/my:table");

    row = row.cloneNode(true);

    row.selectSingleNode("/my:name").text = tempName; var parent=XDocument.DOM.selectSingleNode("myField");

    parent.appendChild(row);

    }

    I get an error that "parent.append.Child(row);" "'null' is null or not an object"

    I am not really sure what is going on here. Any help would be great.

  • 04-21-2008 05:48 AM In reply to

    • Brad87
    • Not Ranked
    • Joined on 04-10-2008
    • Posts 5

    Re: Copy text from one repeating table to another

    InfoPath 2007 / C#

    I'm trying to copy data from a sharepoint list to a repeating table in an infopath form so that it can be viewed when not connected to the sharepoint list. I am trying to copy the data by the click of a button. I've never really done much with infopath before (none with 2007) so any pointers would be appreciated. The following is what I've tried so far. I'm having problems with the current view part. I get an error that says:

    "Either the combination of values for the View.SelectNodes call is an invalid selection, or the values are not defined for this view, defined for this view more than once, or not selectable in the view."

     Any idea how to fix or get around this?

     

    public void CTRL20_5_Clicked(object sender, ClickedEventArgs e)
            {
                // Write your code here.

                XPathNavigator rootMain = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:group5", NamespaceManager);
                XPathNavigator rootSecondary = this.DataSources["Universities"].CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Universities", NamespaceManager);

                // Select nodes in specified XPathNavigator.
                CurrentView.SelectNodes(rootSecondary);


                XPathNodeIterator selectedNodes = CurrentView.GetSelectedNodes();

                XmlWriter writer = rootMain.SelectSingleNode("/my:myFields", NamespaceManager).AppendChild();

                string myNamespace = NamespaceManager.LookupNamespace("my");

                foreach (XPathNavigator selectedNode in selectedNodes)
                {
                    writer.WriteStartElement("group6", myNamespace);
                    writer.WriteElementString("field3", myNamespace, selectedNode.ToString());
                    writer.WriteEndElement();
                }

     

  • 04-21-2008 07:08 AM In reply to

    Re: Copy text from one repeating table to another

    In IP 2007 you can take your data sources off-line.  Which means it will do this caching for you.

    Check it out and see if that is what you need.

  • 04-21-2008 07:33 AM In reply to

    • Brad87
    • Not Ranked
    • Joined on 04-10-2008
    • Posts 5

    Re: Copy text from one repeating table to another

     I've tried enabling that option, but when I save a form that has been populated and reopen it I am asked if I want to connect. If I say no the data is not displayed in the table.

  • 04-21-2008 04:25 PM In reply to

    Re: Copy text from one repeating table to another

    katies12,

    Your code fails to take into account relative XPaths. They are all using absolute XPaths. Relative means from the point of origin, while absolute means from the top/beginning.

    Also "append.Child" doesn't exist, whereas "appendChild" does. I think this might have just been a typo on your part.

    I'm justing winging the changes below and haven't tested them... but maybe they'll help out (It assumes that CTRL26_5 is a button on the repeating row of the table--the context of which is the row node):

    function CTRL26_5::OnClick(eventObj)
    {
    // Write your code here
    var row = eventObj.Source.cloneNode(true);
    row.parentNode.appendChild(row);
    }

    This is greatly simplified. Because you are using cloneNode(true), the field values are copied as well--so there's no need to manually set the name value. If you want to clear the other field's value, you can do that.

  • 04-21-2008 04:36 PM In reply to

    Re: Copy text from one repeating table to another

    Brad87,

    The feature Clay refers to is on the second to last page of the data connection wizard. There is a check box labeled "Store a copy of the data  in the form template". Be sure the select this check box.

    When you open the form offline, a dialog box will appear stating that it failed to connect to the data source and ask whether you want to work offline. Click the "Work Offline" button and the stored data will be available to you. To update the stored data, just rebuild your data connection in the same manner.

  • 05-04-2008 08:03 PM In reply to

    Re: Copy text from one repeating table to another

    Hello I have the same problem. When I use C# code as this

    public void CTRL20_5_Clicked(object sender, ClickedEventArgs e)
            {
                // Write your code here.

                XPathNavigator rootMain = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:group5", NamespaceManager);
                XPathNavigator rootSecondary = this.DataSources["Universities"].CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Universities", NamespaceManager);

                // Select nodes in specified XPathNavigator.
                CurrentView.SelectNodes(rootSecondary);


                XPathNodeIterator selectedNodes = CurrentView.GetSelectedNodes();

                XmlWriter writer = rootMain.SelectSingleNode("/my:myFields", NamespaceManager).AppendChild();

                string myNamespace = NamespaceManager.LookupNamespace("my");

                foreach (XPathNavigator selectedNode in selectedNodes)
                {
                    writer.WriteStartElement("group6", myNamespace);
                    writer.WriteElementString("field3", myNamespace, selectedNode.ToString());
                    writer.WriteEndElement();
                }

     

    It shows the error at  XPathNodeIterator selectedNodes = CurrentView.GetSelectedNodes();
    which says Microsoft.Office.InfoPath.View does not contain a definition for selectNodes.

    Which I want to do is like this. The "Name" and "age" I will get from DB and the attachment is from Infopath's attachment control. There will be a repeating table which contains the second data source(the name and age from DB) and the main data source(the attachment). So I want to copy the data from second data source to the main datasource use c# code. can you help me? thanks 

    Name age attachment
    willson 28
    peter 32

  • 05-05-2008 03:37 PM In reply to

    Re: Copy text from one repeating table to another

    You started off okay using "MainDataSource" but then started using "CurrentView". These are not the same thing. The view is what is visually displayed to the user. The MainDataSource is the data that is displayed in the view.

    If you are trying to access nodes or values, you should be using a data source (MainDataSource or DataSources["dsNameHere"]).

  • 05-06-2008 02:22 AM In reply to

    Re: Copy text from one repeating table to another

    Hi thanks for suggestion Here's my new code

    XPathNavigator rootMain = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:Demo", NamespaceManager);
                XPathNavigator rootSecondary = this.DataSources["Demo"].CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields", NamespaceManager);
                
                XPathNodeIterator selectnodes = rootSecondary.Select("d:Demo",NamespaceManager);
               
                XmlWriter writer = rootMain.SelectSingleNode("/my:myFields", NamespaceManager).AppendChild();
               
                string myNameSpace = NamespaceManager.LookupNamespace("my");
                foreach(XPathNavigator node in selectnodes)
                {
                      writer.WriteStartElement("Demo",myNameSpace);
                      writer.WriteElementString("name",myNameSpace,node.getAttribute("Name",""));
                      writer.WriteElementString("Age",myNameSpace,node.getAttribute("Age",""));
                      writer.WriteEndElement();

                }
                I can get the data by node.getAttribute("Name","")

                but it can't write into the main datasource. Is there anything wrong?

                Thanks

  • 05-06-2008 04:18 PM In reply to

    Re: Copy text from one repeating table to another

    What are you using to develop your code in? Visual Studio should have caught the fact that "getAttribute()" is not valid... the capitalization is wrong. It should be "GetAttribute()".

    If that doesn't work, you can always get an attribute value this way: node.SelectSingleNode("@Name").Value

  • 05-06-2008 07:34 PM In reply to

    Re: Copy text from one repeating table to another

    Sorry the code is not copy past here so there maybe have some spelling error.

    I can get the attribute value.

    but it seems I can't write it into the main datasource.

    Is there anything wrong?

    ( I edit a little for XMLWriter)

    XmlWriter writer = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields", NamespaceManager).AppendChild();

    Thanks

  • 05-06-2008 08:08 PM In reply to

    Re: Copy text from one repeating table to another

    Thanks alot

    I have solve the problem.

  • 05-06-2008 11:56 PM In reply to

    Re: Copy text from one repeating table to another

    The last question

    how to add a attachment node into the repeating table.

    I found the infopath create the element <my:attach xsi:nil="true"></my:attach>

    and my is <my:attach/>

  • 05-07-2008 04:15 PM In reply to

    Re: Copy text from one repeating table to another

    You use xsi:nil="true" if you don't want the user to be required to fill out the field (or in this case, attach a file). Without that attribute, the field will be required by the user (i.e. red asterisk).

    It's your choice really. If you add the attribute, you'll need to follow all the rules for adding an attribute with a namespace.

Page 2 of 4 (50 items) < Previous 1 2 3 4 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.