accessing repeating table node - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

accessing repeating table node

Last post 03-06-2009 06:52 AM by JermaineCross. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 10-04-2005 04:15 PM

    accessing repeating table node

    Does anyone know how to directly access a particular row
    in a repeating table. I want to go down the list of
    rows after the user has entered them and save off the data.
    I could use the e.site.selectsinglenode("..") to get the
    current row, but I actually want to reference row 3 directly
    not just the current row.

    I could save off the data as the user enters the repeating rows
    , but I would rather find a way to reference each row directly
    because I don't need to pass the information to a web service
    until later on after the form is been passed to other userroles
    in my workflow.

    Thanks.

  • 10-04-2005 09:51 PM In reply to

    • nkelkar
    • Not Ranked
    • Joined on 09-30-2005
    • Canada
    • Posts 11

    Re: accessing repeating table node

    A check to see if there 'really' are 3 rows or not:

    Dim numRows = thisXDocument.DOM.selectNodes("//d:RepeatingTable").length()
    if numRows >= 3 then
    Dim cellValue = thisXDocument.DOM.selectSingleNode("//d:RepeatingTable[" & 3 & "]/@CellYouWant")).text
    else
    ' Place logic here
    end if

    The trick is you could iterate through the entire rows by making i as increment as follows:
    --
    Dim numRows = thisXDocument.DOM.selectNodes("//d:RepeatingTable").length()
    For i = 1 To numRows
    ' do something with the statement below, just a pointer to the cell value.
    thisXDocument.DOM.selectSingleNode("//d:RepeatingTable[" & i & "]/@CellYouWant")).text
    Next
    --

    Convert the code as needed, its in vb.net

    Hope that helps.

    NK
  • 10-05-2005 06:22 AM In reply to

    Re: accessing repeating table node

    Don't know if this is because I use JScript, but I would think this function is available in VB.NET too. Anyway, here's how I do it:


    var repeatingTable = XDocument.DOM.selectNodes( "/my:Data/my:group1/my:group2" );

    while( row = repeatingTable.nextNode() )
    {
    save( row.selectSingleNode( "my:cell1" ) );
    save( row.selectSingleNode( "my:cell2" ) );
    //etc.
    }


    ---------------
    Matt Faus
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 10-11-2005 09:17 AM In reply to

    Re: accessing repeating table node

    Hi

    I've tried to apply your method to solve my problem (see: http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=1001' target='_blank' title='>http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=1001'>http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=1001). It's not exactly what I needed to do but just wanted to see how I can access repeating table nodes on different rows.

    It seems to me there is something wrong with the syntax on this line:

    thisXDocument.DOM.selectSingleNode("//d:RepeatingTable[" & i & "]/@CellYouWant")).text

    (I've tried it with and w/o the 2nd parenthesis before ".text"). Either way code couldn't access a node on row i. Error message I am getting is: "Object reference not set to an instance of an object".

    Does any one know what is the right syntax of accesing a node on particular row in a repeating table (in vb.net preferably)?

    Thanks!



    quote:
    Originally posted by nkelkar

    A check to see if there 'really' are 3 rows or not:

    Dim numRows = thisXDocument.DOM.selectNodes("//d:RepeatingTable").length()
    if numRows >= 3 then
    Dim cellValue = thisXDocument.DOM.selectSingleNode("//d:RepeatingTable[" & 3 & "]/@CellYouWant")).text
    else
    ' Place logic here
    end if

    The trick is you could iterate through the entire rows by making i as increment as follows:
    --
    Dim numRows = thisXDocument.DOM.selectNodes("//d:RepeatingTable").length()
    For i = 1 To numRows
    ' do something with the statement below, just a pointer to the cell value.
    thisXDocument.DOM.selectSingleNode("//d:RepeatingTable[" & i & "]/@CellYouWant")).text
    Next
    --

    Convert the code as needed, its in vb.net

    Hope that helps.

    NK

  • 10-11-2005 10:12 AM In reply to

    Re: accessing repeating table node

    I found an answer to myself:) If somebody finds it helpful here is my code that calculates subtotals for each row of a repeating table:


    Dim numRows As Integer = _
    thisXDocument.DOM.selectNodes("//my:repeatingTable").length()

    Dim i As Integer

    For i = 1 To numRows

    Dim field1 As Double = _
    CDbl(thisXDocument.DOM.selectSingleNode("//my:repeatingTable[" & i & "]/my:field1").text)
    Dim field2 As Double = _
    CDbl(thisXDocument.DOM.selectSingleNode("//my:repeatingTable[" & i & "]/my:field2").text)
    Dim subtotal As Double = field1 + field2
    Dim nodeSubtotal As IXMLDOMNode = _
    thisXDocument.DOM.selectSingleNode("/my:repeatingTable[" & i & "]/my:Subtotal")
    nodeSubtotal.text = CStr(subtotal)

    Next






    quote:
    Originally posted by puziuss

    Hi

    I've tried to apply your method to solve my problem (see: http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=1001' target='_blank' title='>http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=1001'>http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=1001). It's not exactly what I needed to do but just wanted to see how I can access repeating table nodes on different rows.

    It seems to me there is something wrong with the syntax on this line:

    thisXDocument.DOM.selectSingleNode("//d:RepeatingTable[" & i & "]/@CellYouWant")).text

    (I've tried it with and w/o the 2nd parenthesis before ".text"). Either way code couldn't access a node on row i. Error message I am getting is: "Object reference not set to an instance of an object".

    Does any one know what is the right syntax of accesing a node on particular row in a repeating table (in vb.net preferably)?

    Thanks!



    quote:
    Originally posted by nkelkar

    A check to see if there 'really' are 3 rows or not:

    Dim numRows = thisXDocument.DOM.selectNodes("//d:RepeatingTable").length()
    if numRows >= 3 then
    Dim cellValue = thisXDocument.DOM.selectSingleNode("//d:RepeatingTable[" & 3 & "]/@CellYouWant")).text
    else
    ' Place logic here
    end if

    The trick is you could iterate through the entire rows by making i as increment as follows:
    --
    Dim numRows = thisXDocument.DOM.selectNodes("//d:RepeatingTable").length()
    For i = 1 To numRows
    ' do something with the statement below, just a pointer to the cell value.
    thisXDocument.DOM.selectSingleNode("//d:RepeatingTable[" & i & "]/@CellYouWant")).text
    Next
    --

    Convert the code as needed, its in vb.net

    Hope that helps.

    NK



  • 10-11-2005 11:52 AM In reply to

    Re: accessing repeating table node

    The Code I gave would have done exactly what you were trying to do, with slight modifications.

    var repeatingTable = XDocument.DOM.selectNodes( "/my:Data/my:group1/my:group2" );
    var sum = 0;

    while( row = repeatingTable.nextNode() )
    {
    var subtotal = getNodeTypedValue(row.selectSingleNode( "my:line_item_total" ));
    sum += subtotal;
    }


    With, of course, conversions between language syntax. Also, you don't have to go to the trouble of getting the number of rows, blah blah blah.

    ---------------
    Matt Faus
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 10-11-2005 02:47 PM In reply to

    Re: accessing repeating table node

    That's right, thanks Matt. The only thing is that the main purpose of my "workaround" was to figure out how I could get an index of a repeating table node (or row) where exactly the change event occured. Indeed, I don't need all subtotals re-calculated every time when only one field's value changes. I only need a subtotal for that particular row calculated! Still can't work it out... I wish there was something like thisXDocument.DOM.selectSingleNode("//nodeName").nodeIndex as there is .nodeValue or .text:)
    Any ideas?

    Thanks!

    quote:
    Originally posted by MFaus

    The Code I gave would have done exactly what you were trying to do, with slight modifications.

    var repeatingTable = XDocument.DOM.selectNodes( "/my:Data/my:group1/my:group2" );
    var sum = 0;

    while( row = repeatingTable.nextNode() )
    {
    var subtotal = getNodeTypedValue(row.selectSingleNode( "my:line_item_total" ));
    sum += subtotal;
    }


    With, of course, conversions between language syntax. Also, you don't have to go to the trouble of getting the number of rows, blah blah blah.

    ---------------
    Matt Faus


  • 10-12-2005 07:12 AM In reply to

    Re: accessing repeating table node

    Oh, OK. I gotcha. I have had to do this recently and I understand your frustration. Here's what I did:

    1) Go tohttp://www.infopathdev.com/howto/tutorials/default.aspx?i=d663d7df90e94e65abb02632966e8127 and implement this to get a autogenerated row ID for each row in the table.

    2) Make a function kind of like this to obtain the row ID:

    function findRowID( item ) // any node within the table is passed in
    {
    var parent = item.parentNode;

    // iterate up through the levels of the table until we find the ROW node
    while( parent.nodeName != "my:group2" )
    parent = parent.parentNode;

    // when loop exits we have ROW node
    var id = parent.selectSingleNode( "my:row_ID" );

    return parseInteger(id.text);
    }

    3) Now, you should execute onAfterChange() on the ROW node, so it would be something like row::onAfterChange( eventObj ). This way if anything in this row changes, calculate the new total. If you're looking to do the calculations in another function, simply call findRowID( eventObj.Site ), or you could pass any other node within the table, and use the rowID returned to call something like
    XDocument.DOM.selectSingleNode( "//my:group1/my:group2[my:rowID = " + rowID + "]" )

    The biggest help to me was the InfoPathDev tutorial. Hope this helps!

    ---------------
    Matt Faus
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 03-03-2009 09:49 AM In reply to

    Re: accessing repeating table node

    I have a similiar problem but I am using JS with a SQL connection. My code is:

    var iField = eventObj.Source.selectSingleNode("../d:TimeSheetDetail/@In1"); iField.text = "";

    var oField = eventObj.Source.selectSingleNode("../d:TimeSheetDetail/@Out1"); oField.text = "";

    var holField = eventObj.Source.selectSingleNode("../d:TimeSheetDetail/@Holiday"); holField.text = "8";

    I can't get the row to update the current row only the first row updats. Any suggestions would be greatly appreciated.

  • 03-03-2009 04:02 PM In reply to

    Re: accessing repeating table node

    If d:TimeSheetDetail is the repeating field/group, then I have a feeling you should use:

    var iField = eventObj.Source.selectSingleNode("@In1");

    and so on.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 03-06-2009 06:52 AM In reply to

    Re: accessing repeating table node

     

    thanks a million! i thought i tried that first but i guess i didn't. I really appreciate ur help.
Page 1 of 1 (11 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.