Using a text field to populate a Repeating table - InfoPath Dev
in

InfoPath Dev

Using a text field to populate a Repeating table

Last post 04-11-2011 02:58 AM by Anonymous. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 02-17-2009 11:38 AM

    Using a text field to populate a Repeating table

    All,

     I have a text field that I do work on in a script.  The script is kicked off by a button and after the script runs, I want to be able to take the data generated and populate a new row in a repeating table.

    I have the part about creating a new row in the table using XDocument.View.ExecuteAction "xCollection::insert", "group2_44" and everything works great... for the first entry.

     Every other entry after that is then placed in the first row ... and ... a new row is created too.

     How do I get the data to appear in the new row instead of in the first row?

     The flow is something like..
    1.  Enter Data
    2.  Click Button
    3.  Data is generated in script
    4.  Data is populated in current row in repeating table
    5.  New row is generated in table
    6.  New row is selected
    7.  Repeat from #1

  • 02-17-2009 07:09 PM In reply to

    Re: Using a text field to populate a Repeating table

    To select the last row (most recently added) in a repeating group, you can use the XPath last() function, so if the path to your repeating group was /my:myFields/my:group1/my:group2, you could do something like this:

        XDocument.View.ExecuteAction "xCollection::insert", "group2_44"

        Set newRow = XDocument.DOM.selectSingleNode("/my:myFields/my:group1/my:group2[last()]")
        newRow.selectSingleNode("my:field1").text = "Some text"
        newRow.selectSingleNode("my:field2").text = "Some other text"

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-17-2009 07:14 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Using a text field to populate a Repeating table

    Hello,

    While inserting new row you have to set your data into that node. After setting the data you have to insert your new node.

  • 02-18-2009 09:26 AM In reply to

    Re: Using a text field to populate a Repeating table

    Worked as listed.  Thank you for the help!

  • 04-07-2011 09:35 AM In reply to

    Re: Using a text field to populate a Repeating table

    Hi Jimmy, hoping you can help me out!

    I have used the info in this post to create some code that inserts a new row in a repeating table and sets the value of a field in the new (last) row of that table on the click of a button.  The code works brilliantly on one view of my form and works exactly as it should so I've tried to replicate the code to perform the exact same function on a differnt view of the form, using a different button.

    Unfortunately it doens't seem to be working - I'm getting the following error when debugging the code:

    InfoPath has encountered an error. The operation failed.
    
    The form's code contains an error.

    The following call in the form's code failed: View.ExecuteAction
    Unknown name.

     

    I've pasted the code below and would really appreciate it if you could take a look and let me know what's going wrong - I'm not a developer and not really have any code experience other than hacking at samples I've nicked off of here!  One thing to note is that the repeating table being updated is on an enitrely separate view to both of the buttons that are firing the code.  On one of the posts I read it said that you need to have a copy of the repeating table on the same view as the button to fire the code or the code won't work so I have copies of the repeating table on both views that are hidden via conditional formatting.

    Also of note is the fact that if I remove the second set of code, the first button works correctly (e.g. inserts a new row, sets the field value, submits and closes the form); if I remove the first portion of code and leave the second portion however, I still get the same error!

    Hopefully this all makes sense!

     

    Imports Microsoft.Office.InfoPath
    Imports System
    Imports System.Windows.Forms
    Imports System.Xml
    Imports System.Xml.XPath
    Imports mshtml


    Namespace Purchase_Order_Form_V2._0
        Public Class FormCode
            ' Member variables are not supported in browser-enabled forms.
            ' Instead, write and read these values from the FormState
            ' dictionary using code such as the following:
            '
            ' Private Property _memberVariable() As Object
            '     Get
            '         _memberVariable = FormState("_memberVariable")
            '     End Get
            '     Set
            '         FormState("_memberVariable") = value
            '     End Set
            ' End Property

            ' NOTE: The following procedure is required by Microsoft InfoPath.
            ' It can be modified using Microsoft InfoPath.
            Private Sub InternalStartup(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Startup
                AddHandler DirectCast(EventManager.ControlEvents("CTRL126"), ButtonEvent).Clicked, AddressOf CTRL126_Clicked

                AddHandler DirectCast(EventManager.ControlEvents("CTRL201"), ButtonEvent).Clicked, AddressOf CTRL201_Clicked
            End Sub

            Public Sub CTRL126_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
                CurrentView.ExecuteAction(ActionType.XCollectionInsert, "PurchaseOrderStatusGroup_300")

                Dim PurchaseOrderStatus As XPathNavigator = _
       Me.MainDataSource.CreateNavigator().SelectSingleNode( _
          "/my:PurchaseOrder/my:FinanceSummary/my:PurchaseOrderStatusGroup[last()]/my:POStatus", NamespaceManager)
                PurchaseOrderStatus.SetValue("PO Cancelled by Requestor")

                Dim fileSubmit As FileSubmitConnection = CType(Me.DataConnections("SharePoint Library Submit"), Microsoft.Office.InfoPath.FileSubmitConnection)

                fileSubmit.Execute()

                Me.Close()

            End Sub
         

            Public Sub CTRL201_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
                CurrentView.ExecuteAction(ActionType.XCollectionInsert, "PurchaseOrderStatusGroup_328")

                Dim PurchaseOrderStatus As XPathNavigator = _
       Me.MainDataSource.CreateNavigator().SelectSingleNode( _
          "/my:PurchaseOrder/my:FinanceSummary/my:PurchaseOrderStatusGroup[last()]/my:POStatus", NamespaceManager)
                PurchaseOrderStatus.SetValue("PO Cancelled by Requestor")

                Dim fileSubmit As FileSubmitConnection = CType(Me.DataConnections("SharePoint Library Submit"), Microsoft.Office.InfoPath.FileSubmitConnection)

                fileSubmit.Execute()

                Me.Close()

            End Sub
        End Class
    End Namespace

  • 04-07-2011 09:13 PM In reply to

    Re: Using a text field to populate a Repeating table

    Hi Ben,

    We developed qRules to handle this kind of support. Please download a free trial of that and see if you can get it working. We did this because we were spending a lot of time answering the same questions in the forum. Insert was one of those questions. You know we spend thousands of dollars a month to keep this forum going and the forum makes us no money. qRules was an attempt to help people and also help us not incur such a loss. We appreciate your support and we're also sure that you will get tons of value out of qRules, including the programmatic Insert functionality, which is just one of the 50+ features that your can leverage.

    Thanks for your understanding.

    Note: If you are using InfoPath 2003, you can't use qRules. qRules works with InfoPath 2007 and 2010 and suppors browser forms.

    Patrick Halstead
    Project Manager at Qdabra
  • 04-08-2011 01:14 AM In reply to

    Re: Using a text field to populate a Repeating table

    Thanks Patrick. I am aware of qRules but not sure if my IT department will allow me to install me it - I will look into further.

    On a side note, I would like to say thanks to you guys for all the effort and support you do provide in this forum, I know that without a doubt I'd be completely lost without it and the help you guys have provided me has really enabled me to make huge improvements in my InfoPath forms!

  • 04-08-2011 02:33 AM In reply to

    Re: Using a text field to populate a Repeating table

    Hey Ben,

    Thanks for the kind words. We do give significant discounts for testimonials. If you approve of your first name and last name initial appearing on our website along with the text above we can offer you a big discount on qRules or we could even help you a little more with your code. :) 

    At any rate, you may not need IT approval. qRules installs in the form template. You only need IT approval if you are installing into a SharePoint site and want to have it run in the browser forms and you are on MOSS 2007 - that requires SharePoint Central Admin access to approve the form template. On SharePoint 2010, with the Sandbox enabled, you only need Site Collection Admin privileges.  But, keep in mind you only need that help if you are deploying as a browser form to SharePoint. If they are opening thef orms in InfoPath client, no special privileges are needed.

    Cheers!

    Patrick Halstead
    Project Manager at Qdabra
  • 04-08-2011 03:02 AM In reply to

    Re: Using a text field to populate a Repeating table

    Hi Patrick, I have just had my IT department install the qRules trial now and am in the process of figuring out how it all works, but it certainly seems more straight forward than struggling with code!

    As far as testimonials go, I'm more than happy for you to use my words...our company relies heavily on InfoPath but there are only a handful of us that have fairly advanced InfoPath skills (and none of us are IT/programmers!).  I can without a doubt say that my InfoPath skills would be nowhere near where they are without this site, and that's even after being on half a dozen training courses!

     I'll let you know how I get on with qRules!

  • 04-08-2011 08:13 AM In reply to

    Re: Using a text field to populate a Repeating table

    Hi Ben,

    Thanks for your support. We know you'll love all of the wonderful features in qRules. We do free weekly webinars on Thursday at 8am PST and go over qRules features. Please send email to QdSales *at* Qdabra *dot* com for your discount code.

    Great thing about qRules is it will save you time and maintenance cost and you'll get a ton of new features to use to enhance your forms. With the free weekly webinars every week, you'll become a qRules slinging InfoPath master in no time.

    Let us know if you have any questions. Lots of howto labs out there to dive into ...

    Patrick Halstead
    Project Manager at Qdabra
  • 04-08-2011 08:15 AM In reply to

    Re: Using a text field to populate a Repeating table

    Ok, next question...qRules is working great for me so far and I've managed to sort out inserting a new row with the "Insert" command.  I am now working on setting the value of a field in the repeating table using the "SetValue" command; this is working fine except that the command updates all the fields in the repeating table and I only want to update the last field.  I found this post http://www.infopathdev.com/forums/p/17777/62033.aspx#62033 where Hilary mentions using count(preceding::ns1:Clients) + 1 and have tried to utilise this in my form but it's just returning a massive error message:

     Action: SetValue. Arguments: xpath: :myPurchaseOrder/my:FinanceSummary/my:PurchaseOrderStatusGroup[1]/my:POStatus
    value: PO Authorised - Awaiting Invoice
    . Details: ':myPurchaseOrder/my:FinanceSummary/my:PurchaseOrderStatusGroup[1]/my:POStatus' has an invalid token.. Stack:    at MS.Internal.Xml.XPath.XPathScanner.NextLex()
       at MS.Internal.Xml.XPath.XPathScanner..ctor(String xpathExpr)
       at MS.Internal.Xml.XPath.XPathParser.ParseXPathExpresion(String xpathExpresion)
       at MS.Internal.Xml.XPath.QueryBuilder.Build(String query, Boolean allowVar, Boolean allowKey)
       at MS.Internal.Xml.XPath.QueryBuilder.Build(String query, Boolean& needContext)
       at System.Xml.XPath.XPathExpression.Compile(String xpath, IXmlNamespaceResolver nsResolver)
       at System.Xml.XPath.XPathNavigator.Select(String xpath, IXmlNamespaceResolver resolver)
       at Qdabra.Tools.RulesLibrary.Commands.GetValidNodeSet(XPathNavigator dom, String xpath)
       at Qdabra.Tools.RulesLibrary.Commands.SetValue()
       at Qdabra.Tools.RulesLibrary.Commands.ExecuteCommand()

    The command I have used is: concat("SetValue /xpath=:myPurchaseOrder/my:FinanceSummary/my:PurchaseOrderStatusGroup[", count(preceding::PurchaseOrderStatusGroup) + 1, "]/my:POStatus /value=", FormOpeningView)

    The "POStatus" field is being set by another field in the form that isn't contained within the repeating section and I don't have anyway of filtering the repeating table to indicate that only the last row should be updated like in the sample form.  Any suggestions??

     

  • 04-08-2011 10:50 AM In reply to

    Re: Using a text field to populate a Repeating table

    Hey Ben -- note for the future -- if you create a new thread in the qRules forum we'll be more likely to see this than tacking it on here....

    That said, your XPath in your command is incorrect:

    concat("SetValue /xpath=:myPurchaseOrder/my:FinanceSummary/my:PurchaseOrderStatusGroup[", count(preceding::PurchaseOrderStatusGroup) + 1, "]/my:POStatus /value=", FormOpeningView)

    Should probably be:

    concat("SetValue /xpath=my:myPurchaseOrder/my:FinanceSummary/my:PurchaseOrderStatusGroup[", count(preceding::PurchaseOrderStatusGroup) + 1, "]/my:POStatus /value=", FormOpeningView)

    Note that I added the "my" namespace right after the equals sign.

    Hilary Stoupa

  • 04-11-2011 02:58 AM In reply to

    Re: Using a text field to populate a Repeating table

    Thanks so much Hilary, amazing how 2 missing letters can cause so much frustration!  I will remember to post future questions in a new thread but hopefully you can help out one last time in this one...

    The rule is now working and along with the "insert" rule inserts a new row into my repeating table and updates the status field.  The problem I'm still having is getting the last record to update.  Using [",count(preceding::PurchaseOrderStatusGroup) +1,"] updates the status field in the very first status group (which is there by defatult) so I tried doing +2.  This appeared to work as it was updating the newly inserted row but the problem I'm encountering is that if a new row is inserted the command is once again updating the 2nd repeating group rather than the last!

    The idea for this button is to automatically set a number of status updates based on actions taken within the form so it's really crucial that I get this concept of "insert new row, update record on newly inserted row" correct.

    Thanks again for all your help, massively appreciated as always :)

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