Can you use Visual basic script to delete all repeating rows of a node? - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Can you use Visual basic script to delete all repeating rows of a node?

Last post 02-16-2012 12:45 AM by Jimmy. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 02-15-2012 04:46 AM

    Can you use Visual basic script to delete all repeating rows of a node?

    Can you use Visual basic script to delete all repeating rows of a node?

     What I tried was:

    While Me.CreateNavigator().SelectSingleNode("/my:myFields/my:Form_Container/my:SET/my:SET_Members[last()]/my:SET_Mem_WinID", Me.NamespaceManager).Value <> Nothing

     

    Me.CreateNavigator().SelectSingleNode("/my:myFields/my:Form_Container/my:SET/my:SET_Members[last()]/my:SET_Mem_WinID", Me.NamespaceManager).DeleteSelf()

    End While

    But it doesn't work. SET_Members is a repeating node and SET_Mem_WinID is the node's text field. Every time a form loads, I am trying to clear all repeating values in SET_Members so that I can re-populate the list all over again.

     

    I will repopulate by using this:

     

    Me.CreateNavigator().SelectSingleNode("/my:myFields/my:Form_Container/my:SET/my:SET_Members[last()]/my:SET_Mem_WinID", Me.NamespaceManager).SetValue("ABCD")

    Me.CreateNavigator().SelectSingleNode("/my:myFields/my:Form_Container/my:SET", Me.NamespaceManager)

    .AppendChild(

    Me.CreateNavigator().SelectSingleNode("/my:myFields/my:Form_Container/my:SET/my:SET_Members[last()]", Me.NamespaceManager)

    )

  • 02-15-2012 11:07 AM In reply to

    Re: Can you use Visual basic script to delete all repeating rows of a node?

    An alternative you can look into is to use qRules which easily allows you to delete rows of a repeating table without code. More info: http://www.qdabra.com/en/products/qRules_top.aspx
    Anson Hidajat
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

  • 02-15-2012 11:17 AM In reply to

    Re: Can you use Visual basic script to delete all repeating rows of a node?

    It might work if you remove this from that first line: .Value

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-15-2012 07:49 PM In reply to

    • Skarn
    • Top 50 Contributor
      Male
    • Joined on 04-20-2008
    • Australia
    • Posts 198

    Re: Can you use Visual basic script to delete all repeating rows of a node?

    Also, if you are intending to delete the actual repeating node, and not one of its children you may only need my:SET_Members[last()] without the WinID references - otherwise all the nodes will still be there, they just won't have the WinId field anymore.

  • 02-15-2012 07:54 PM In reply to

    • Skarn
    • Top 50 Contributor
      Male
    • Joined on 04-20-2008
    • Australia
    • Posts 198

    Re: Can you use Visual basic script to delete all repeating rows of a node?

    Wait, do you mean VBScript or VB Net? The code you are using is not VBScript.

    Also, in VBScript the test would be:

    While Not (Me.CreateNavigator().SelectSingleNode("/my:myFields/my:Form_Container/my:SET/my:SET_Members[last()]/my:SET_Mem_WinID", Me.NamespaceManager) Is Nothing)

    Testing for "Not Is Nothing" in VB Net may be similar - "<> Nothing" could be a problem.

  • 02-15-2012 08:02 PM In reply to

    Re: Can you use Visual basic script to delete all repeating rows of a node?

    Hi,

     I'm using Visual Basic. Not VB Net or VBScript. Under the form's Tools-Form Options-Programming- Programming code, it is listed as "Visual Basic".

     To explain things, I have a Group: SET which has a Repeating group called SET_Members and it has a string field: "SET_Mem_WinID". For existing forms, SET_Mem_WinID will look like a repeating table with values:

    A

    B

    C

    D

    However, everytime I open existing forms, I want A,B,C,D to be deleted and I will repopulate the list of members. How can this be done using Visual Basic code?

    By the way, the purpose of A,B,C,D is meant for the form's user roles. So this code is stored as a loading event.

     

    Thank!

  • 02-15-2012 08:29 PM In reply to

    Re: Can you use Visual basic script to delete all repeating rows of a node?

    Found the solution!

    While Me.CreateNavigator().SelectSingleNode("/my:myFields/my:Form_Container/my:SET/my:SET_Members", Me.NamespaceManager) IsNot Nothing

    Me.CreateNavigator().SelectSingleNode("/my:myFields/my:Form_Container/my:SET/my:SET_Members", Me.NamespaceManager).DeleteSelf()

    End While

    Me.CreateNavigator().SelectSingleNode("/my:myFields/my:Form_Container/my:SET", Me.NamespaceManager).AppendChild(

    Me.CreateNavigator().SelectSingleNode("/my:myFields/my:Form_Container/my:SET/my:SET_Members[last()]", Me.NamespaceManager))

     

    Without the AppendChild statement, my while statement was deleting all nodes and my subsequent codes were not able to add names to the new list. Somehow (don't ask me why the append works, I'm no guru) after many many trial and errors, I got this append to work!

    Next, to find out how can I load a form's user roles directly from a database table... this will make maintenance so much easier... I think I've tried a data connection before but I think the data connection loads AFTER the form loading event and so the form roles were not populated in time. Any suggestions on this?

     We prefer not to have to use qRules :)

  • 02-15-2012 10:37 PM In reply to

    • Skarn
    • Top 50 Contributor
      Male
    • Joined on 04-20-2008
    • Australia
    • Posts 198

    Re: Can you use Visual basic script to delete all repeating rows of a node?

    Hmmm, well the While loop you have should indeed delete all the SET_Members nodes.
    As a result I would expect your AppendChild to fail because the child you are asking it to append should no longer exist - you've just deleted them all in the While loop!

    It might be a behaviour of VB language, but I would expect your AppendChild line to fail as  Me.CreateNavigator().SelectSingleNode("/my:myFields/my:Form_Container/my:SET/my:SET_Members[last()]", Me.NamespaceManager) would be 'Nothing'.

  • 02-16-2012 12:45 AM In reply to

    Re: Can you use Visual basic script to delete all repeating rows of a node?

    For a much easier time, I recomment using qRules' Delete and Insert commands.  With about 5 minutes and 2 commands, you can do everything you're trying to accomplish here, and in a much more robust manner.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (9 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.