Request for assistance on VB to delete row on repeating table based on fixed value - InfoPath Dev
in

InfoPath Dev

Request for assistance on VB to delete row on repeating table based on fixed value

Last post 03-09-2017 08:17 AM by blkmagik. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 02-21-2017 03:44 PM

    Request for assistance on VB to delete row on repeating table based on fixed value

    Hello Is it possible to assign a vb scrip to a button that will delete all rows in a repeating table based on a fixed value Ive tried messing around with the vb script but im constantly getting erorrs. So far i have Dim rowList rowList = XDocument.DOM.selectNodes("/my:myFields/my:group3/my:group4") For Each row In rowList Dim field1Value field1Value = row.selectSingleNode("my:DELETEROW").text If (field1Value = "false") Then row.parentNode.removeChild(row) End If Next I am getting a variable deceleration and protection level errors when i try to debug the core. Thanks in advance
  • 02-22-2017 07:28 AM In reply to

    Re: Request for assistance on VB to delete row on repeating table based on fixed value

     What version of InfoPath are you using?

    Hilary Stoupa

  • 02-22-2017 08:14 AM In reply to

    Re: Request for assistance on VB to delete row on repeating table based on fixed value

    Hi Hilary I am currently using Infopath Designer 2013
  • 02-22-2017 03:07 PM In reply to

    Re: Request for assistance on VB to delete row on repeating table based on fixed value

     I'm sorry for the delay, for some reason your replies are ending up in the moderation queue. I had to add some additional SPAM controls after a recent attack and seem to be getting some false positives on moderation. So - if you are using IP 2013, that means you are using Visual Studio 2012? I think you may be following code samples for VB script, not VB.NET. This code sample may help you out: http://www.bizsupportonline.net/infopath2007/programmatically-delete-all-rows-repeating-table-infopath.htm

    Hilary Stoupa

  • 02-24-2017 07:20 AM In reply to

    Re: Request for assistance on VB to delete row on repeating table based on fixed value

    Thanks Hilary

    I looked at the code and tested it and it worked. However when i included the IF Statement which gave me no errors nothing seems to happen. I created 2 if statements to test out and both gave no results. Im wondering if im doing the syntax all wrong.

    Public Sub CTRL752_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
                ' Write your code here.
                ' Retrieve a reference to the Main DOM
                Dim root As XPathNavigator = MainDataSource.CreateNavigator()

                'Ist attempt
                'Dim GetValue As Object
                'GetValue = "DELETE"
                'If GetValue = ("//my:myFields/my:group3/my:group4/my:DELETEROW") Then

                '2nd attempt
                Dim fieldValue As String = MainDataSource.CreateNavigator().SelectSingleNode( _
                "/my:myFields/my:group3/my:group4", NamespaceManager).Value
                If fieldValue = "delete" Then

                    ' Count the amount of group2 nodes
                    Dim iter As XPathNodeIterator = root.Select( _
                   "/my:myFields/my:group3/my:group4", _
                   NamespaceManager)
                    Dim group2NodesCount As Integer = iter.Count

                    ' Retrieve the first group2 node
                    Dim firstGroup2NodeNav As XPathNavigator = _
                   root.SelectSingleNode("/my:myFields/my:group3/my:group4[1]", _
                    NamespaceManager)

                    ' Retrieve the last group2 node
                    Dim lastGroup2NodeNav As XPathNavigator = _
                    root.SelectSingleNode("/my:myFields/my:group3/my:group4[" & _
                    group2NodesCount.ToString() & "]", _
                    NamespaceManager)


                    ' Delete the range of nodes from the first to the last group2 nodes
                    firstGroup2NodeNav.DeleteRange(lastGroup2NodeNav)
                End If
            End Sub

  • 02-24-2017 07:38 AM In reply to

    Re: Request for assistance on VB to delete row on repeating table based on fixed value

     Run your code in debug so you can see what is going on - here's a post on how to do that. My guess is that "group4" doesn't have a value of "delete".

    Hilary Stoupa

  • 03-07-2017 01:00 PM In reply to

    Re: Request for assistance on VB to delete row on repeating table based on fixed value

    Hilary i looked up the link your provided but wasn't able to figure it out since i seem to be using a different version of VSTA is there any other way for me to edit the code below to only retrieve the firstGroup2NodeNav and the lastGroup2NodeNav nodes based on a what the end user selects off a dropdown list box? I was trying to familiarize myself with xpath syntax and tried to use //COMPANY[@SELECTDELETE] but that doesnt seem to work =================================================== Public Sub CTRL686_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs) ' Write your code here. ' Retrieve a reference to the Main DOM Dim root As XPathNavigator = MainDataSource.CreateNavigator() ' Count the amount of group2 nodes Dim iter As XPathNodeIterator = root.Select( _ "/my:myFields/my:group3/my:group4", _ NamespaceManager) Dim group2NodesCount As Integer = iter.Count ' Retrieve the first group2 node Dim firstGroup2NodeNav As XPathNavigator = _ root.SelectSingleNode("/my:myFields/my:group3/my:group4[1]", _ NamespaceManager) ' Retrieve the last group2 node Dim lastGroup2NodeNav As XPathNavigator = _ root.SelectSingleNode("/my:myFields/my:group3/my:group4[" & _ group2NodesCount.ToString() & "]", _ NamespaceManager) ' Delete the range of nodes from the first to the last group2 nodes firstGroup2NodeNav.DeleteRange(lastGroup2NodeNav) ' End Sub
  • 03-07-2017 03:40 PM In reply to

    Re: Request for assistance on VB to delete row on repeating table based on fixed value

     Sorry your posts got caught in the moderation queue. The basic steps to run your code in debug should work no matter which version of InfoPath you are using - mark a break point in the code and start from the code editor instead of from preview. The XPath you pasted - //COMPANY[@SELECTDELETE] - appears to be invalid? You don't have a SELECTDELETE attribute on the COMPANY node in the main data source & you are missing your namespace prefixes.

    Are you committed to VB.NET? What is your end goal here - the user will mark the rows they wish to delete? Using the DELETEROW field? I can put together a quick sample tomorrow, but would prefer to use C#.... 

    Hilary Stoupa

  • 03-08-2017 07:20 AM In reply to

    Re: Request for assistance on VB to delete row on repeating table based on fixed value

    Unfortunately i am not committed to vb.net. My original end goal was essentially to populate the SELECTDELETE drop down list with a list of Company names. Once the the end user selected a company name the DELETEROW would then be flagged with the word "delete" for the VB script to use and determine the node ranges to delete. I think im over complicating things this way and thought maybe i can omit the DELETEROW field and simply have a script identify the company name selected in the SELECTDELETE drop down list and delete any instance of the same company name found on form. Is this possible? Thanks again in advance
  • 03-08-2017 12:05 PM In reply to

    Re: Request for assistance on VB to delete row on repeating table based on fixed value

     Yes - that is possible. The code on your button would look something like this, based off the Test template you attached earlier:

                ' Get value for company to delete
                Dim company As String = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:SELECTDELETE", NamespaceManager).Value

                'Get nodes matched on company
                Dim nodesToDelete As XPathNodeIterator = MainDataSource.CreateNavigator().Select(String.Format("/my:myFields/my:group3/my:group4[my:COMPANY = '{0}']", company), NamespaceManager)

                'create list for storing nodes we will delete - DeleteSelf() directly on the node within the loop will cause it to break.
                Dim nodeList As System.Collections.ArrayList = New System.Collections.ArrayList()

                For Each nodeToDelete As XPathNavigator In nodesToDelete
                    nodeList.Add(nodeToDelete.Clone())
                Next

                For Each nodeToDelete As XPathNavigator In nodeList
                    nodeToDelete.DeleteSelf()
                Next 

    Hilary Stoupa

  • 03-09-2017 08:17 AM In reply to

    Re: Request for assistance on VB to delete row on repeating table based on fixed value

    Thanks that worked, appreciate your assistance on this.
Page 1 of 1 (11 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.