How to retrieve the value from a previous column in a repeating table (filled from secondary datasource) - InfoPath Dev
in

InfoPath Dev

How to retrieve the value from a previous column in a repeating table (filled from secondary datasource)

Last post 02-28-2008 03:10 PM by Greg Collins. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 02-28-2008 02:46 AM

    How to retrieve the value from a previous column in a repeating table (filled from secondary datasource)

    1 secondary repeating tabelset containt information from a webservice

    1 primary  repeating table that i'm filling up with information from the secondary tableset

    ****** 

    [ code]

    var myclone=XDocument.DOM.selectSingleNode("/my:myFields/my:R_group/my:RT_directreports").cloneNode(true);      //clone of primary datatable

    XDocument.DOM.selectNodes("/my:myFields/my:R_group/my:RT_directreports").removeAll();           //make sure there's nothing in before filling up

    var nodes=XDocument.GetDOM("pricing").selectNodes("/dfs:myFields/dfs:dataFields/tns:pricingResponse/tns:pricingResult/NewDataSet/Table");    //secondary datasource

    for (var i=0; i < nodes.length; i++)

    {

    var curregion=nodes(i).selectSingleNode("REGION").text ; //fetch current region

    --> HERE<-- 

    I'ld like to retrieve the value of the previous rowset from the secondary datasource  and then do a compare..

    If it the previous sibling would be different (region change from let's say 'USA' to 'EMEA' or "LATAM'", i'ld first enter a blank tableline - to make it more distinguishable.

     

    //XDocument.UI.Alert(curregion + prevregion);

    myclone.selectSingleNode("my:F_Region").text = nodes(i).selectSingleNode("REGION").text;      // fill primary cloned rowset with datafields from secondary rowset

    myclone.selectSingleNode("my:F_Country").text = nodes(i).selectSingleNode("C").text;

    myclone.selectSingleNode("my:F_Lastname").text = nodes(i).selectSingleNode("SN").text;

    myclone.selectSingleNode("my:F_Firstname").text = nodes(i).selectSingleNode("GIVENNAME").text; 

     

    etc.etc..

     

    I looked at preceding-sibling stuff but find a bit complex to get through

    ??  var prevregion=nodes(i).selectSingleNode("preceding-sibling::REGION").text ; //fetch previous region

     

     

    tnxs

    K
     

    KriZ
  • 02-28-2008 03:10 PM In reply to

    Re: How to retrieve the value from a previous column in a repeating table (filled from secondary datasource)

    var nodes=XDocument.GetDOM("pricing").selectNodes("/dfs:myFields/dfs:dataFields/tns:pricingResponse/tns:pricingResult/NewDataSet/Table");    //secondary datasource

    for (var i=0; i < nodes.length; i++)
    {
        var curregion=nodes(i).selectSingleNode("REGION").text ; //fetch current region

    There are two ways to do this.

    1. Check to make sure i > 0, and then do: 
        var prevregion=nodes(i-1).selectSingleNode("REGION").text ; //fetch previous region

    2. Use an XPath:
        var prevregion=nodes(i).selectSingleNode("preceding-sibling::Table[1]/REGION").text ; //fetch previous region

    The reason your preceding-sibling axis didn't work is because you were trying to access a non-existent node. nodes(i) refers to "Table" and not "REGION'. Therefore, the preceding-sibling will also point to "Table". You need to make sure to put "[1]" so that the XPath knows you only want to go back 1 preceding-sibling... otherwise it might try to go all the way back (i.e. same as "[last()]").

    Either way you choose, you'll need to make sure you have a valid node before attempting to access the .text property or you will get an exception.

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