Node Count - InfoPath Dev
in

InfoPath Dev

Node Count

Last post 08-05-2008 01:42 AM by ben.oates. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 08-04-2008 07:08 AM

    Node Count

    Afternoon,

    I've been looking around for code that can do this for a few days and all the samples I find use an XDocument.View node select method as part of the code. I don't actually have all of the nodes that I want to look at in the views that I am calling the function from, so (as far as I understand it - which isn't very far) that is why this code does not work for me.

    This is VBScript. I have tried a number of different methods but can't get one to work. My first attempt involved view but I think I got the XPath wrong and as discussed earlier don't think I can use View anyway. I also can't get XDocument.DOM.CreateNavigator to work as I found in other examples.

    My data source is structured as follows:

    • myFields
      • Hardware (Repeating)
        • HWID
      • Software (Repeating)
        • SWID
      • Order (Repeating)
        • HWID (Repeating)
        • SWID (Repeating)

    There are many other fields but these are the important ones at the moment. Each order is populated with hardware/software that was filled in in the other two lists. If the number of items in Hardware or Software is zero I want to remove all items in HWID or SWID lists respectively so as to avoid confusion with less observant users.

    Does anyone have any suggestions on how I might go about this? 2 examples of my many attempts are below and fail miserably.

    I have tried:

    Dim objNode
     Dim objNodes
     Dim ordNodes
     Dim ordObjNodes
     
     objNode = XDocument.DOM.selectSingleNode ("//my:myFields/my:Hardware")
     XDocument.View.SelectNodes objXMLNode
     
     objNodes = XDocument.View.GetSelectedNodes
     
     objNode = XDocument.DOM.selectSingleNode ("//my:myFields/my:Order")
     XDocument.View.SelectNodes objXMLNode
     
     ordNodes = XDocument.View.GetSelectedNodes
     
     objNode = XDocument.DOM.selectSingleNode ("//my:myFields/my:Order/my:HWID")
     XDocument.View.SelectNodes objXMLNode
     
     ordObjNodes = XDocument.View.GetSelectedNodes
     
     if objNodes.Count > 0 Then
      'If there are hardware items, make sure there is at least one in the orders
     Else
      'If there are no hardware items, remove all hardware items from the orders
     End If

    And:

    xpn = XDocument.Dom.CreateNavigator

     

    hNode = xpn.selectSingleNode ("//my:myFields/my:Hardware", NamespaceManager)

     

    oNode = xpn.selectSingleNode ("//my:myFields/my:Order", NamespaceManager)

     

    idNode = XDocument.GetNamedNodeProperty (oNode,"my:HWID","Unknown")

     

    if hNode.Count > 0 Then

    'If there are hardware items, make sure there is at least one in the orders

    Else

    'If there are no hardware items, remove all hardware items from the orders

    End If

  • 08-04-2008 04:31 PM In reply to

    Hi --

    VBScript uses the 2003 object model, so you won't be able to use CreateNavigator with it -- that is for IP 2007 managed code (C# or VB.NET).

    So, if I am reading this right, you need to select some nodes in your form and get a count, do one thing if the count is zero and other if it isn't... does that sum it up?

    This snipped of VBScript will get a repeating group and pop up a message box telling you how many nodes are in it:

    Dim objNodes

    Set objNodes = XDocument.DOM.selectNodes("/my:myFields/my:Hardware")

    MsgBox objNodes.length

    And here is some information from MSDN on the selectNodes method -- which I think is more along the lines of what you need. Hopefully this will get you started on the right path, but let me know if you need more help, okay?

    Hilary Stoupa

  • 08-05-2008 01:42 AM In reply to

    Ah! Thank you so much! This is actually where I started but the example I had found didn't have Set at the start of the line. That makes all the difference in the world!

    I am so new to programming Infopath. Thank you for your help. I think I can work the rest of this out from that link.

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