Reading values of a repeating table and writing them to a string value... - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Reading values of a repeating table and writing them to a string value...

Last post 01-13-2011 07:37 AM by sheist. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 01-12-2011 10:24 AM

    • sheist
    • Not Ranked
    • Joined on 01-12-2011
    • Posts 8

    Reading values of a repeating table and writing them to a string value...

    I am trying to use vbscript to generate an email based on the data collected from a form.  This email is text only and needs to read the information from a repeating table popluated by a user (hostname and IP address).

    I've been able to figure out how to read the first row... but the for loop I thought would work doesn't increment for me.  I'm a noob to both infopath and vbscript, so I'm hoping someone can help me out....

    Here's the code:

    Dim oLastRow

    dim a

    a = 0

    dim b

    b = XDocument.DOM.selectSingleNode("//my:countrules").Text  'hidden field to get the number of rows in the table

    for a = 1 to b+1

    Set oLastRow = XDocument.DOM.selectNodes("//my:myFields/my:Addrulegroup/my:addrulegroup/my:addruletable[a]")

    src = XDocument.DOM.selectSingleNode("//my:srcname").Text

    srcaddr = XDocument.DOM.selectSingleNode("//my:addsrc").Text 

    rowdata = src & " " & srcaddr & vbcrlf

    psbody = psbody & rowdata    'appends the row to the body of the email

    a = a + 1 'increments my counter (a)

    next

     

    Maybe someone knows a better way... thanks in advance for the help. 

     

  • 01-12-2011 11:49 AM In reply to

    Re: Reading values of a repeating table and writing them to a string value...

    Hi, I think you have to replace XDocument.DOM for oLastRow on your loop. 

    Set oLastRow = XDocument.DOM.selectNodes("//my:myFields/my:Addrulegroup/my:addrulegroup/my:addruletable[a]")

    src = oLastRow .selectSingleNode("//my:srcname").Text

    srcaddr = oLastRow .selectSingleNode("//my:addsrc").Text 

  • 01-12-2011 12:01 PM In reply to

    • sheist
    • Not Ranked
    • Joined on 01-12-2011
    • Posts 8

    Re: Reading values of a repeating table and writing them to a string value...

    I actually tried that too, but I'm getting an error saying that "the object is not available" or something like that..

  • 01-12-2011 01:14 PM In reply to

    • sheist
    • Not Ranked
    • Joined on 01-12-2011
    • Posts 8

    Re: Reading values of a repeating table and writing them to a string value...

    This is the error.. 

     

    Object doesn't support this property or method: 'oLastRow.selectSingleNode'

  • 01-12-2011 01:55 PM In reply to

    Re: Reading values of a repeating table and writing them to a string value...

    Set oLastRow = XDocument.DOM.selectNodes("//my:myFields/my:Addrulegroup/my:addrulegroup/my:addruletable[a]")

    is selecting a set of nodes.

    Perhaps this:

    Set oLastRow = XDocument.DOM.selectSingleNode("//my:myFields/my:Addrulegroup/my:addrulegroup/my:addruletable[a]")

    would work better, then follow Potemkine's suggestion -- although I'm perplexed where you are setting a = 0, then saying:

    for a = 1 to b+1

    You'd never enter your for loop, would you?

    Hilary Stoupa

  • 01-13-2011 07:35 AM In reply to

    • sheist
    • Not Ranked
    • Joined on 01-12-2011
    • Posts 8

    Re: Reading values of a repeating table and writing them to a string value...

    OK, gave your suggestion a try.  It yields a new error:

     Object required: 'oLastRow'

    Here's the code...

    for a = 1 to b+1
     Dim oLastRow
     Set oLastRow = XDocument.DOM.selectSingleNode("//my:myFields/my:Addrulegroup/my:addrulegroup/my:addruletable[a]")
     src = oLastRow.selectSingleNode("//my:srcname").Text
     srcaddr = oLastRow.selectSingleNode("//my:addsrc").Text
     rowdata = src & "     " & srcaddr  & vbcrlf
     psbody = psbody & rowdata
     'msgbox(rowdata)
     a = a + 1

  • 01-13-2011 07:37 AM In reply to

    • sheist
    • Not Ranked
    • Joined on 01-12-2011
    • Posts 8

    Re: Reading values of a repeating table and writing them to a string value...

    and I changed the assignment of a to "a=1"...

    thanks for catching that, and your help!

  • 01-13-2011 07:55 AM In reply to

    Re: Reading values of a repeating table and writing them to a string value...

    a is a variable in your code, but selectSinbleNode() has no idea what a is.  If you want to use a in your XPath, you have to concatenate it in:

    Set oLastRow = XDocument.DOM.selectSingleNode("//my:myFields/my:Addrulegroup/my:addrulegroup/my:addruletable[" & a & "]")

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-13-2011 08:16 AM In reply to

    • sheist
    • Not Ranked
    • Joined on 01-12-2011
    • Posts 8

    Re: Reading values of a repeating table and writing them to a string value...

    Thanks! 

    OK, so this stopped throwing the "Object Required" error, but it still doesn't iterate through the rows in the table... it just reads the first row over and over...

     I've also tried clearing the variables for src and srcaddr inside the loop (i.e. src = "")

    I also noticed that my loop is for some reason skipping a=2.... it just jumps from a=1 to a=3... any thoughts on that?

  • 01-13-2011 01:35 PM In reply to

    • sheist
    • Not Ranked
    • Joined on 01-12-2011
    • Posts 8

    Re: Reading values of a repeating table and writing them to a string value...

    Here is another example where I use very similar code... it works for the first row in a repeating table, but then not after that.  It takes a hostname as input and does an nslookup for the IP by calling a function I found online "DNSLookup()".  I'm still assuming that my issue is with how I am declaring/calling the [in this case the last] row of the repeating table.  Thanks again for the help!

    Sub msoxd_my_srcname_OnAfterChange(eventObj)

    ' Write code here to restore the global state.

    dim test
    dim hostname
    dim oLastRow
    Set oLastRow = XDocument.DOM.selectSingleNode("//my:myFields/my:Addrulegroup/my:addrulegroup[last()]")
    hostname = oLastRow.selectSingleNode("//my:srcname").Text
    test = DNSLookup(hostname)
    oLastRow.selectSingleNode("//my:addsrc").Text = test
    If eventObj.IsUndoRedo Then
     ' An undo or redo operation has occurred and the DOM is read-only.
     Exit Sub
    End If

    ' A field change has occurred and the DOM is writable. Write code here to respond to the changes.

    End Sub

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