in

InfoPath Dev

Simple Code to Add Row

Last post 07-26-2008 06:43 AM by PJagger. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 07-08-2008 08:43 AM

    • PJagger
    • Top 200 Contributor
      Male
    • Joined on 11-19-2007
    • Australia
    • Posts 29

    Simple Code to Add Row

    Hello,

    I am exhasted by all the post on this subject (both in this forum and on the web) that are absolutely confusing and vague.  I wan't a simple JScript code to add a new (BLANK) row into a repeating table triggered by a field element (outside of the repeating table) on-change event.  I already have a simple code to do this via a button:

    XDocument.View.ExecuteAction("xCollection::insert", "xcollection")

     ...however, surely there is a way to achieve the same without a button and without all the cloning hooha.

    Please help me, and before referring me back to the maze of futile posts, please respect that I have spent many hours already trying to find a simple definitive solution but to no avail.

    Regards Phil 

    Filed under: , ,
  • 07-08-2008 03:51 PM In reply to

    Re: Simple Code to Add Row

    Hi, Phil:

    You sound frustrated. I think one of the issues is that every scenario is so different -- the data sources and the xpaths and so forth -- it does leave the waters looking muddy. There shouldn't be a problem hooking to the onChange event of a field outside of the table. To prevent having it fire twice, you'll want to use an if statement to make sure that you only fire it on insert on your changing field, because once a field has a value, when you modify it, it changes twice -- once to delete the old value, and once when it accepts the new value.

    if(eventObj.Operation == "Insert")
      {
         XDocument.View.ExecuteAction("xCollection::insert", "repeatingGroup_2")
      }

    The above code in the onChange event of your field will only fire on insert operations, and, of course, you need to change "repeatingGroup_2" to the ID of your table. I hope this helps, but please let me know if you need more information, okay?

    Hilary Stoupa / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 07-08-2008 05:02 PM In reply to

    • PJagger
    • Top 200 Contributor
      Male
    • Joined on 11-19-2007
    • Australia
    • Posts 29

    Re: Simple Code to Add Row

    Hi Hilary,

    Thank you so much for your prompt reply.  I am somewhat frustrated but still optomistic.  I have already tried what you have suggested.  I have tried again since your reply.  I have used both the xcollection reference from the table in the view, and also the xpath ID from the repeating table data source.  Nothing happens - not even an error message.

    It works when placed behind a button, but not behind the onAfterChange event on a field in the parent group.

    NB.  I've tried changing the data in the trigger field both automatically and manually. 

    Regards - Phil

  • 07-08-2008 06:12 PM In reply to

    Re: Simple Code to Add Row

    So, just to clarify so I can try to replicate -- you have a group with a field and a repeating group in it, and you want the rows to be added when that field changes?

    Hilary Stoupa / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 07-11-2008 12:36 AM In reply to

    • PJagger
    • Top 200 Contributor
      Male
    • Joined on 11-19-2007
    • Australia
    • Posts 29

    Re: Simple Code to Add Row

    You got it Hilary

    Regards - Phil

  • 07-11-2008 07:48 AM In reply to

    Re: Simple Code to Add Row

    Oh, dear. Because that is exactly how I set up the sample I used to test. For the spot where I have "repeatingGroup_2", you would put the name for your repeating table -- I'm probably telling you something you already know, but to find that, right click on your table, select Repeating Table Properties, and, under the Advanced tab, look in the Code section. The name you are looking for is next to the label XMLToEdit for xCollection.

    Hilary Stoupa / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 07-25-2008 05:09 PM In reply to

    • PJagger
    • Top 200 Contributor
      Male
    • Joined on 11-19-2007
    • Australia
    • Posts 29

    Re: Simple Code to Add Row

    Hi Hilary,

    Sorry for the delayed response.  I have been acutely ill and bedridden.

    I have done all this.  This process works for me with a button, however, when I place the trigger field in the section on screen (same section that it lives in) and manually increment the number, I get an error with the same programming that was used for the button, but obviously attached to the 'on after change event' process for that field.  When I manually increment the field, I get theis message: 'The specified bstr Action for the View.ExecuteAction call is not applicable for the current selection. File:script.js.  Line:487'

    And of course line 487 refers to the above 'on after change event'.

    Regards - Phil

  • 07-25-2008 05:31 PM In reply to

    Re: Simple Code to Add Row

    I'm sorry to hear you've been ill. Is this form something you can share? If so, I'd like to take a look at it. If not, let me know, and I'll send or post the sample I used.

    Hilary Stoupa / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 07-26-2008 06:43 AM In reply to

    • PJagger
    • Top 200 Contributor
      Male
    • Joined on 11-19-2007
    • Australia
    • Posts 29

    Re: Simple Code to Add Row

    Hi Hilary,

    I'm happy to share the form with you, but it is not an easily stand alone form.  It has several data connections to form libraries on a sharepoint site along with calculated fields from those data connections. Nonetheless, I will forward it to you, I have doctored it a little for you to work with more easily.  If the form opens, the field with the programming in question is "test".  Simply place a number in the field to trigger an 'on after change' event.

    Good luck.

    Phil

    BTW I need your email address to attach the form.

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