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 1 of 4 (50 items) 1 2 3 4 Next >
Sort Posts: Previous Next
  • 05-30-2007 06:38 AM

    Copy text from one repeating table to another

    Hi all,

    I have looked at several (lots!) of the posts here and other places about repeating tables and code and just cannot get my head around how to solve my problem.

    I have a structure, as below in IP2003 with two repeating tables.

    MainLog
     Assumptions
      AssumptionID (Whole Number)
      AssumptionDate (Date)
      Assumption (Text)
      CopiedToRisks (Boolean)
     Risks
      RiskID (Whole Number)
      RiskDate (Date)
      Risk (Text)
      AssumptionID (Whole Number)
      Assumption (text)

    All initial data entry is made in the Assumptions repeating table. I have a button in each row, where if needed, the user clicks and the following occurs:

    • A new entry in the Risks repeating table is added and the AssumptionID and Assumption text is copied from the Assumptions repeating table into the new row.
    • The CopiedToRisks flag is updated to TRUE in the Assumptions repeating table.

    When I have a non repeating table, I can get the values from the fields by using:

    var txtAssumption = XDocument.DOM.selectSingleNode("/my:MainLog/my:Assumptions/my:Assumption").text

    and then use the cloneNode and parent.appendChild code that I have found elesewhere on the site.

    So, how do I get the values from a repeating row...

    Many thanks

    Graham

  • 05-30-2007 09:33 AM In reply to

    Re: Copy text from one repeating table to another

    The key is understanding what is available in the eventObj parameter. From here you can get to eventObj.Source which is the row node in your repeating table. Why? The context of a button in a repeating table row is always the repeat table row.

    Once you know that, you can do eventObj.Source.selectSingleNode("my:TextField").text to get the value you want to copy.

    Since you have created a clone in memory that you are appending to the Risks, you already have access to the new row to be able to copy values.

    Hope that helps.

  • 05-30-2007 10:00 AM In reply to

    Re: Copy text from one repeating table to another

    OK, thanks, that worked, I can now pull the values from the relevant row in the repeating table.

    So, I have added the code below to add those values into a new cloned row in Risks

    var tempID = eventObj.Source.selectSingleNode("my:AssumptionID").text;

    var tempAssumption = eventObj.Source.selectSingleNode("my:Assumption").text;

    var row = XDocument.DOM.selectSingleNode("/my:IARLog/my:Risks");

    row = row.cloneNode(true);

    row.selectSingleNode("my:AssumptionID").text = tempID

    row.selectSingleNode("my:Assumption").text = tempAssumption

    var parent = XDocument.DOM.selectSingleNode("/my:IARLog");

    parent.appendChild(row);

    and I receive the following error :

    Element '{http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-05-30T15:15:16}Risks' is unexpected according to content model of parent element '{http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-05-30T15:15:16}IARLog'.

    File:script.js
    Line:34

    This occurs on the parent.appendChild(row) line of code.

     

    Thanks

  • 05-31-2007 11:14 AM In reply to

    Re: Copy text from one repeating table to another

    Solved!

    I had some additional fields in the data source structure. Once I had moved them to the top and the "Risks" repeating group was at the very bottom...all works fine :-)

     

    Graham

  • 06-04-2007 09:40 AM In reply to

    Re: Copy text from one repeating table to another

    Great!! Glad to hear you got it working!

    Great job! Keep up the good work!

  • 02-12-2008 10:02 AM In reply to

    Re: Copy text from one repeating table to another

    Hi
    I have similar needs and I was hoping someone could help me out.  I have an InfoPath form "A" that generates a report by using published fields from form "B" located on a sherpoint forms library. Now I need to be able to edit the data in form "A"

    Is there some code or rule I can use to copy data from my secondary data source into a "mirrored" repeating table to my primary data source so it can be edited and saved?
    Note: my secondary data source is dynamic hence the number of rows may vary depending on the filter so my repeating table needs to generate the same number of rows.

    Example

    myFields
         dataFields
            SecondaryDataSource
                   Field1(read only)
                   Field2(read only)
                   Field3(read only)

    myFields
         PrimaryDataSource
                   Field1(can edit)
                   Field2(can edit)
                   Field3(can edit)


    Thanks

    @lphamax
  • 02-13-2008 02:56 PM In reply to

    Re: Copy text from one repeating table to another

    You will certainly need code for this as rules does not allow for the insertion of new rows.

    If you had the foresight to know you were going to do this, you could have ensured that the namespace used in Form A and Form B was identical, that would make copying from one to the other very simple. But in all likelyhood they are different. Therefore, you will need to write a code routine which loops through the repeater in your 2DS and manually copies to the main DOM by creating a new row, populating it, and then inserting it. (First though, make sure you delete any existing rows in the main DOM).

  • 02-14-2008 09:59 AM In reply to

    Re: Copy text from one repeating table to another

    Thanks for the advice. Do you know any code online that does something similer to what I am trying to do. I am not a hardcore programmer so just need a place to start

     

    Thanks

    Thanks

    @lphamax
  • 02-14-2008 12:24 PM In reply to

    Re: Copy text from one repeating table to another

    What version of InfoPath and coding language are you planning to use? IP07 or 03? C#/VB, JScript/VBScript?

  • 02-15-2008 09:04 PM In reply to

    Re: Copy text from one repeating table to another

    InfoPath 2003 and JScript

     

    Thanks

    Thanks

    @lphamax
  • 02-19-2008 11:09 AM In reply to

    Re: Copy text from one repeating table to another

    The following was just written from memory and not tested. There might be some syntax errors in it, but it should give you a good idea of what needs to be done:

     

    // Get a copy of the main DOM node.
    var clone = XDocument.DOM.selectSingleNode("/my:myFields/my:PrimaryDataSource").cloneNode(true);

    // Clear the main DOM nodes.
    XDocument.DOM.selectNodes("/my:myFields/my:PrimaryDataSource").removeAll();

    // Copy nodes from 2DS to main DOM.
    var nodes = XDocument.GetDOM("SecondaryDataSource").selectNodes("/myFields/dataFields/SecondaryDataSource"); // Note: need to supply the correct namespace per element in this XPath.
    foreach(var node in nodes)
    {
     clone.selectSingleNode("my:Field1").text = node.selectSingleNode("Field1").text;
     clone.selectSingleNode("my:Field2").text = node.selectSingleNode("Field2").text;
     clone.selectSingleNode("my:Field3").text = node.selectSingleNode("Field3").text;

     XDocument.DOM.selectSingleNode("my:myFields").appendChild(clone.cloneNode(true));
    }

  • 02-19-2008 02:08 PM In reply to

    Re: Copy text from one repeating table to another

    Thanks a million. Will let you know if I run into any issues

    Thanks

    Thanks

    @lphamax
  • 02-21-2008 01:01 PM In reply to

    Re: Copy text from one repeating table to another

    Glad to have helped!

  • 02-25-2008 03:56 PM In reply to

    Re: Copy text from one repeating table to another

    Hi, i've tried to follow what you've listed but I'm missing something, but what?

    I keep getting an error ( Object doesn't support this property or method) on the section in bold . If i uncomment the DOM and GETDOM sections to declare the namespace, it's the same error..

    Primary Datasource= Repeating Table called RT_directreports, containing a couple of fields

    Secondary Datasource(pricing) = Repeating Table through an Oracle Webservice 

     

     function CTRL7_5::OnClick(eventObj)

    {

    //XDocument.GetDOM("pricing").SetProperty("SelectionNameSpaces",'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"');

    //XDocument.DOM.SetProperty("selectionNamespaces",'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-02-16T21:00:45"')

     

    var myclone=XDocument.DOM.SelectSingleNode("/my:myFields/my:RT_directreports").cloneNode(true);

    XDocument.DOM.SelectNodes("/my:myFields/my:RT_directreports").Removeall();

     

    var nodes=XDocument.GetDOM("Pricing").SelectNodes("/dfs:myFields/dfs:dataFields/tns:pricingResponse/tns:pricingResult/NewDataSet/Table");

    foreach (node in nodes)

    {

    myclone.selectSingleNode("/my:F_Country").text = node.SelectsingleNode("C").text;

    myclone.selectSingleNode("/my:F_Lastname").text = node.SelectsingleNode("SN").text;

    myclone.selectSingleNode("/my:F_Firstname").text = node.SelectsingleNode("Givenname").text;

    myclone.selectSingleNode("/my:mail").text = node.SelectsingleNode("mail").text; 

    XDocument.DOM.SelectSingleNode("my:myfields").appendChild(clone.cloneNode(true));

    }

     

     

    Yes, i want to get  all the data from the secondary datasource  autofiled into a new table and save that data with the form.

    If i save it like this, the form is empty, it doesn't keep the secondary data in.

    Using infopath 2003 SP2 .

    Appreciate your time and effort

    KriZ
  • 02-25-2008 04:48 PM In reply to

    Re: Copy text from one repeating table to another

    It sounds like you are getting a null on your selection. If that is the case, then .cloneNode() is going to fail.

    OH--NEVER MIND! I see what's going on...

    You are using "S"electSingleNode() whereas you should be using "s"electSingleNode(). Script requires that first letter to be lowercase. If you were using managed code, then it would be uppercase.

    Be sure to check all of your method casing.. it looks like you have quite a few uppercase letters that should be lowercase.

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