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

InfoPath Dev

Qdabra® qRules

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 3 of 4 (50 items) < Previous 1 2 3 4 Next >
Sort Posts: Previous Next
  • 06-09-2008 02:35 AM In reply to

    Re: Copy text from one repeating table to another

    Deleted and posted

  • 06-10-2008 05:30 AM In reply to

    • DMcKinnon
    • Not Ranked
      Male
    • Joined on 06-10-2008
    • Raleigh, NC
    • Posts 3

    Re: Copy text from one repeating table to another

    I have been trying to implement the code here to copy a secondary data source (SharePoint list) to the main data source. The problem is the code is telling me that "node" is undeclared and will not run. If I put "var" in front of "node" it throws a syntax error, and I haven't been able to determine what exactly I am missing.
    I am using JavaScript and IP 2003.

    //NAMESPACESDEFINITION
         XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance"
         xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:dfs=http://schemas.microsoft.com/office/infopath/2003/dataFormSolution
         xmlns:my=http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-05-27T15:30:14
         xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"'); XDocument.GetDOM("Retirement Core Activities").setProperty
            ("SelectionNamespaces",'xmlns:ns1="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"' );
    // /NAMESPACESDEFINITION

    function CTRL273_5::OnClick(eventObj) {
         // Get a copy of the main DOM node. 
         var clone = XDocument.DOM.selectSingleNode("/my:myFields/my:group7/my:group8").cloneNode(true); 
         // Clear the main DOM nodes.
         XDocument.DOM.selectNodes("/my:myFields/my:group7/my:group8").removeAll();
         // Copy nodes from 2DS to main DOM.
         var nodes = XDocument.GetDOM("Retirement Core Activities").selectNodes("/ns1:myFields/ns1:dataFields/ns1:Retirement_Core_Activities");
         foreach(node in nodes)
         {
              clone.selectSingleNode("/my:CoreStatus").text = node.selectSingleNode("STATUS").text;
              clone.selectSingleNode("/my:CoreCompletedDate").text = node.selectSingleNode("COMPLETED_DATE").text;
              clone.selectSingleNode("/my:CoreTechLead").text = node.selectSingleNode("TECH_LEAD").text;
              XDocument.DOM.selectSingleNode("/my:myFields/my:group7/my:group8").appendChild(clone.cloneNode(true));
         }
    }

    Filed under: ,
  • 06-10-2008 06:10 AM In reply to

    Re: Copy text from one repeating table to another

    Hi,

    i might be wrong but are you sure your 'nodes' definition is pointing to the repeating table itself?

     

      var nodes = XDocument.GetDOM("Retirement Core Activities").selectNodes("/ns1:myFields/ns1:dataFields/ns1:Retirement_Core_Activities");

    in the codes it write it's more like..

    var nodes2=XDocument.GetDOM("list_machines").selectNodes("/dfs:myFields/dfs:dataFields/ns2:Landesk_listResponse/ns2:Landesk_listResult/NewDataSet/Table") 

    have a look at the screenshot of my secondary datasource at url below

     http://www.infopathdev.com/forums/p/7371/26922.aspx#26922

     (or search for "scarse information on passing parameter to a secondary datasource" in the forums)

    my secondary datasource is based on a table returned (Landesk_listResponse) as a result (Landesk_listResult) of a query.

    That's not what i can see in your code.

     

    KriZ
  • 06-10-2008 06:30 AM In reply to

    • DMcKinnon
    • Not Ranked
      Male
    • Joined on 06-10-2008
    • Raleigh, NC
    • Posts 3

    Re: Copy text from one repeating table to another

    Thanks for the reply knudde,
          I am reasonably sure "nodes" is getting populated. If I wrap the foreach statement in if(nodes.length > 0) the foreach still runs and throws the error. If I change 0 to 100 the foreach does not run.
          I did try your suggestion but in that case if I again wrap the foreach statement with the if it no longer runs for nodes.length > 0 making me believe that is not the right approach for interfacing with a sharepoint list.

    Thanks for your help

  • 06-17-2008 03:51 PM In reply to

    Re: Copy text from one repeating table to another

    DMcKinnon, when you do a foreach, you need to include the data type of the single item:

    foreach(IXMLDOMNode node in nodes)

    Nevermind--that's for C#. I see you are using JScript. You cannot use foreach in JScript the way you are using it. Try this:

    var node;
    while(node = nodes.nextNode())
    {
    ...
    }

  • 06-18-2008 05:01 AM In reply to

    • DMcKinnon
    • Not Ranked
      Male
    • Joined on 06-10-2008
    • Raleigh, NC
    • Posts 3

    Re: Copy text from one repeating table to another

    Thanks Greg, I will have to try it and see if that works.

    Update: Thanks a lot Greg, that seemed to be my lynch pin problem, after fixing that and a few other minor fixes I was able to get it working perfectly.

    Thanks again

  • 06-19-2008 10:10 AM In reply to

    Re: Copy text from one repeating table to another

    Great! Glad to hear you got it working!

  • 07-25-2008 05:47 AM In reply to

    • eirike
    • Not Ranked
    • Joined on 07-25-2008
    • Posts 3

    Re: Copy text from one repeating table to another

    Hi.

    I have problems with this.. Could you please help?

    here is my code...

     

    public void CTRL19_5_Clicked(object sender, ClickedEventArgs e)

    {

    XPathNavigator rootMain = MainDataSource.CreateNavigator().SelectSingleNode("/my:MineFelt/my:Selected/my:Selected2", NamespaceManager);

    XPathNavigator rootSecondary = this.DataSources["getStorfeIDyrehold"].CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/tns:getStorfeIDyreholdResponse/tns:getStorfeIDyreholdResult/storfeListe", NamespaceManager);

    XPathNodeIterator selectnodes = rootSecondary.Select("getStofeIDyrehold", NamespaceManager);

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

    string myNameSpace = NamespaceManager.LookupNamespace("my");foreach (XPathNavigator node in selectnodes)

    {

    writer.WriteStartElement("S_dyrehold", myNameSpace);

    writer.WriteElementString("S_opprMerkeDyrehold", myNameSpace, node.GetAttribute("S_opprMerkeDyrehold", ""));writer.WriteElementString("S_dodsdato", myNameSpace, node.GetAttribute("S_dodsdato", ""));

    writer.WriteEndElement();

     

    }

  • 01-14-2009 11:43 AM In reply to

    • zxkuqyb
    • Not Ranked
      Male
    • Joined on 01-14-2009
    • Indianapolis, IN
    • Posts 18

    Re: Copy text from one repeating table to another

    Greg,

    The advice and coding guidance you provide on this site is amazing.  I have used several of your examples / methods before and wanted to express my thanks to you for being a solid resource.

    Thomas N. Barrett
  • 01-14-2009 01:22 PM In reply to

    Re: Copy text from one repeating table to another

    Thank you zxjyqyb! It's always nice to hear a good word back! Glad to have been of assistance!

  • 01-27-2009 05:14 AM In reply to

    Copy from a repeating table nested within another repeating table to another repeating table nested within the same row of the parent repeating table!

    Dear Greg,

    I used your code and found it worked excellently!  Now I need to step it up a bit and have got problems:

    <groupA>
        <rowA>
          <fieldA1>
          <groupB>
            <rowB>
              <fieldB2>
            </rowB>
          </groupB>
          <groupC>
            <rowC>
              <fieldC2>
            </rowC>
          </groupC>
        </rowA>
    </groupA>

    In the above (where there are multiple <rowA>'s, <rowB>'s and <rowC>'s, I am trying to copy the value in <fieldB2> to the value in <fieldC2>.  The context of the "Copy" button is <rowB>, so it should be possible to copy to the new context of <rowC> whilst keeping the context of <rowA>.

    The problem is that the context of <rowA> is inaccessible.  Here is the original code (non-nested) that works:

            public void elnCopyToProposed_Clicked(object sender, ClickedEventArgs e)

            {

                // Create temp copy object

                XmlDocument doc = new XmlDocument();

                XmlNode group = null;

                XmlNode node = null;

     

                // Check parent node exists

                if (MainDataSource.CreateNavigator().SelectSingleNode("/my:Case/my:Facilities/my:Proposed/my:Loans",

                        this.NamespaceManager) == null)

                {

                    group = doc.CreateElement("my:Loans", NamespaceManager.LookupNamespace("my"));

                    XmlNode nodeOrphan = doc.CreateElement("my:Loan", NamespaceManager.LookupNamespace("my"));

                    node = group.AppendChild(nodeOrphan);

                }

                else

                {

                    node = doc.CreateElement("my:Loan", NamespaceManager.LookupNamespace("my"));

                }

     

                {

                    // Create and add fields

                    XmlNode fieldOrphan = doc.CreateElement("my:lnBalance", NamespaceManager.LookupNamespace("my"));

                    XmlNode field = node.AppendChild(fieldOrphan);

                    field.InnerXml = e.Source.SelectSingleNode("my:elnBalance", this.NamespaceManager).InnerXml;

     

                    fieldOrphan = doc.CreateElement("my:lnLoanType", NamespaceManager.LookupNamespace("my"));

                    field = node.AppendChild(fieldOrphan);

                    field.InnerXml = e.Source.SelectSingleNode("my:elnLoanType", this.NamespaceManager).InnerXml;

     

                    fieldOrphan = doc.CreateElement("my:lnTermRemaining", NamespaceManager.LookupNamespace("my"));

                    field = node.AppendChild(fieldOrphan);

                    field.InnerXml = e.Source.SelectSingleNode("my:elnOriginalTerm", this.NamespaceManager).InnerXml;

                }

     

                // Add the doc to the main data

                if (group != null)

                {

                    doc.AppendChild(group);

                    MainDataSource.CreateNavigator().SelectSingleNode("/my:Case/my:Facilities/my:Proposed",

                            this.NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());

                }

                else

                {

                    doc.AppendChild(node);

                    MainDataSource.CreateNavigator().SelectSingleNode("/my:Case/my:Facilities/my:Proposed/my:Loans",

                            this.NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());

                }                       

            }

    And the (nested) code that doesn't:

            public void oelnCopyToProposed_Clicked(object sender, ClickedEventArgs e)

            {

                // Create temp copy object

                XmlDocument doc = new XmlDocument();

                XmlNode group = null;

                XmlNode node = null;

     

                // Check parent node exists /my:Case/my:OtherFacilities/my:oFacilities/my:oExisting/my:oeLoans

                if (e.Source.CreateNavigator().SelectSingleNode("ancestor::my:oFacilities/my:oProposed/my:oLoans",

                        this.NamespaceManager) == null)

                {

                    group = doc.CreateElement("my:oeLoans", NamespaceManager.LookupNamespace("my"));

                    XmlNode nodeOrphan = doc.CreateElement("my:oeLoan", NamespaceManager.LookupNamespace("my"));

                    node = group.AppendChild(nodeOrphan);

                }

                else

                {

                    node = doc.CreateElement("my:oeLoan", NamespaceManager.LookupNamespace("my"));

                }

     

                {

                    // Create and add fields

                    XmlNode fieldOrphan = doc.CreateElement("my:olnBalance", NamespaceManager.LookupNamespace("my"));

                    XmlNode field = node.AppendChild(fieldOrphan);

                    field.InnerXml = e.Source.SelectSingleNode("my:oelnBalance", this.NamespaceManager).InnerXml;

     

                    fieldOrphan = doc.CreateElement("my:olnLoanType", NamespaceManager.LookupNamespace("my"));

                    field = node.AppendChild(fieldOrphan);

                    field.InnerXml = e.Source.SelectSingleNode("my:oelnLoanType", this.NamespaceManager).InnerXml;

     

                    fieldOrphan = doc.CreateElement("my:olnTermRemaining", NamespaceManager.LookupNamespace("my"));

                    field = node.AppendChild(fieldOrphan);

                    field.InnerXml = e.Source.SelectSingleNode("my:oelnOriginalTerm", this.NamespaceManager).InnerXml;

                }

     

                // Add the doc to the main data

                if (group != null)

                {

                    doc.AppendChild(group);

                    e.Source.CreateNavigator().SelectSingleNode("ancestor::my:oFacilities/my:oProposed",

                        this.NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());

                }

                else

                {

                    doc.AppendChild(node);

                    e.Source.CreateNavigator().SelectSingleNode("ancestor::my:oFacilities/my:oProposed/my:oLoans",

                        this.NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());

                }

            }

     Note that I am also checking that the target group node exists...  <oFacilities> is structurally equivalent to <rowA> and <oLoans> to <groupC>.

    The line:

                if (e.Source.CreateNavigator().SelectSingleNode("ancestor::my:oFacilities/my:oProposed/my:oLoans",

    instead of:

                if (MainDataSource.CreateNavigator().SelectSingleNode("/my:Case/my:Facilities/my:Proposed/my:Loans",

    is to blame.  The root node of the e.Source is the node relating to the context of the button so there is no ancestor to go up to, but if we go down through MainDataSource, how do we indicate the context of the upper repeating structure?

    When looking into the original problem, a colleague suggested using a calculated field to give the position() of the row.  I think that this might offer the solution to this problem, i.e. adding a calculated field in the lower repeating structure which stores the position() in the upper structure.  I'll try this, but please offer a solution if you can think of one!

    Stu

  • 01-27-2009 07:01 AM In reply to

    Re: Copy from a repeating table nested within another repeating table to another repeating table nested within the same row of the parent repeating table!

    The solution I proposed will not work because InfoPath 2007 Form Services is not compatible with the function "position()" (or "last()" for that matter), i.e the message "Use of unsupported XPath functions, position() or last()" is encountered.

    I suppose there is a way to insert a default value (ideally a guid) into a node using VSTO, otherwise the only viable option is to use "now()" as the default value for an element at the upper repeating table row level, and copy it as the default value for an element at the lower repeating table row level.

    This is a bit of a hack, since if two rows are added to the upper repeating table during the same second, the timestamp will not be unique.  InfoPath doesn't offer any other useful functions, such as rnd() to help making a unique identifier.  This is also an unpleasant solution since the identifier will need to be persisted in the datasource.

    So I am rejecting this hack, and giving up for now, and look forward to you supplying an elegant solution...!

    Stu

  • 05-01-2009 10:08 AM In reply to

    Re: Copy text from one repeating table to another

    My situation is very similar.

     

    I have a form based on a schema XYZ. I also have a secondary data connection to an XML file. I can successfully retreive data from the XML file so I know the connection is working. However, I need to copy the contents of nodes within one node from the XML file to a repeating table in the XYZ form. Both the main source and the secondary source have the same exact namespace. I am currently getting an error message when the function hits this line:

    XDocument.DOM.selectNodes("/xyz:TRAN/xyz:DEALER/xyz:PERSON").removeAll();

     

    I'm not sure what the issue is. First time with jscript in infopath. Please assist...

    Thanks much.

  • 06-04-2009 04:10 AM In reply to

    • anpira
    • Not Ranked
      Female
    • Joined on 06-02-2009
    • Spain
    • Posts 4

    Re: Copy text from one repeating table to another

    Hi everyone,

    First, I want to apologize if this topic already has gone out, but I have searched for the whole forum and do not find a good solution for my problem. I tell you:

     I have an InfoPath 2007 form and I have to copy all the rows from one repeating table to another diferent repeating table with VSTA (C#). I have something like the file attached:

    I need to copy all the rows from tableA in tableB. Another user will be able to complete the rest of the columns of the tableB. I manage to write rows in a repeating table, but I do not manage to be reading row by row each of the fields of a repeating table.

    This is part of my code:

    XPathNavigator main = this.MainDataSource.CreateNavigator();

    XPathNavigator tableA = main.SelectSingleNode("/my:myFields/my:tableA/my:ext_tableA", this.NamespaceManager);

    XPathNavigator tableB = main.SelectSingleNode("/my:myFields/my:tableB/my:ext_tableB", this.NamespaceManager);

    string ns = this.NamespaceManager.LookupNamespace("my");

     

    // I NEED A LOOP AND A READER TO READ FIELD BY FIELD---I don't know how...

    using (XmlWriter escritor = docuDestino.AppendChild())

    {

          escritor.WriteStartElement("ext_tableB", ns);

          escritorWriteElementString("placeB", ns, >>fiel i have read from placeA<<);

          escritorWriteElementString("nameB", ns, >>fiel i have read from nameA<<);

          escritor.WriteEndElement();

          escritor.Close();

    }

    The code is incomplete because I don't know how to read all the rows of the tableA. I know that it is a great effort for your part, but...I need your help!

    Thank you for everything.


    Filed under: , ,
  • 02-24-2010 07:39 PM In reply to

    Re: Copy text from one repeating table to another

     Hi Greg, thanks for all your valuable feedback.

    I am trying to do the same thing, moving text from one repeating table to another. I actually have about 5 repeating tables. BUt, I keep getting the following error, whenever I try to add a row to the repeating table, whenever the code parent.appendChild(templeteRow) runs.

    THE ERROR:

    System.Runtime.InteropServices.COMException
    Element '{http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-08T11-28-21}OutagePersonalGrid' is unexpected according to content model of parent element '{http://schemas.microsoft.com/office/infopath/2003/myXSD/2010-02-08T11-28-21}ReportFields'.

     Sometimes when I move my repeating table, that is  the "OutagePersonalGrid" in the error above, around the Data Source, this error does not occur. However, since I have many repeating tables, I am confused as to move which table to where in the datasource. I am using Infopath 2003.

    Why does this issue come in Infopath 2003. How can I totally get rid of it, is there a workaround?

     

    - Sari.

     

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