Simple Code to Add Row - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Simple Code to Add Row

Last post 08-21-2017 04:04 PM by Hilary Stoupa. 24 replies.
Page 1 of 2 (25 items) 1 2 Next >
Sort Posts: Previous Next
  • 07-08-2008 08:43 AM

    • PJagger
    • Top 500 Contributor
      Male
    • Joined on 11-20-2007
    • Australia
    • Posts 40

    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

    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

  • 07-08-2008 05:02 PM In reply to

    • PJagger
    • Top 500 Contributor
      Male
    • Joined on 11-20-2007
    • Australia
    • Posts 40

    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

    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

  • 07-11-2008 12:36 AM In reply to

    • PJagger
    • Top 500 Contributor
      Male
    • Joined on 11-20-2007
    • Australia
    • Posts 40

    You got it Hilary

    Regards - Phil

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

    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

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

    • PJagger
    • Top 500 Contributor
      Male
    • Joined on 11-20-2007
    • Australia
    • Posts 40

    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

    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

  • 07-26-2008 06:43 AM In reply to

    • PJagger
    • Top 500 Contributor
      Male
    • Joined on 11-20-2007
    • Australia
    • Posts 40

    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.

  • 03-02-2009 08:38 AM In reply to

    • drake
    • Not Ranked
      Female
    • Joined on 02-27-2009
    • Minneapolis
    • Posts 22

     You don't by chance have a handy c# version do you?  I've already gotten too far in my form to go to .js now and not break it.

    I tired using the c# version from here this morning: http://aspalliance.com/667_CodeSnip_Add_Row_to_InfoPath_Repeating_Table_on_Button_Click 

    Which worked fine, as long as I didn't have anything in groups (and you answered why I couldn't get it to work in groups here), but go figure, now that I try to use that, blank template and all, it doesn't work.  Says there is a build error.  No idea what I did.  /cry

     

    Edit:
    Oh yay me!  I successfully stripped all c# and I can swap to .js now.  At least one thing has worked today.

  • 03-02-2009 03:32 PM In reply to

    Glad you worked it out.  Just since you asked, this is the code to add a row in C#:

    CurrentView.ExecuteAction(ActionType.XCollectionInsert, "group2_1");

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-02-2010 01:35 AM In reply to

    • PJagger
    • Top 500 Contributor
      Male
    • Joined on 11-20-2007
    • Australia
    • Posts 40

    Hi Hilary,

    I have been out of the loop for quite some time, however, I'm am back on some infopath projects, but now I have to learn to reapply snippets using vbscript (given that infopath 2010 has made a sharp turn on scripting options).  May I trouble you to give me the equivalent vbcode for the following Jscript to add a blank row to a repeating table via a button?

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

     Appreciate all your help

    Phil

  • 12-02-2010 07:02 AM In reply to

    It would be the same, but without the parentheses (replace the first one with a space):

    http://www.infopathdev.com/blogs/jimmy/archive/2009/03/06/automatically-adding-rows-to-repeating-sections.aspx

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-03-2010 03:41 AM In reply to

    • PJagger
    • Top 500 Contributor
      Male
    • Joined on 11-20-2007
    • Australia
    • Posts 40

    Thank you!

  • 12-07-2010 04:31 AM In reply to

    • PJagger
    • Top 500 Contributor
      Male
    • Joined on 11-20-2007
    • Australia
    • Posts 40

    May I impose a little further?

    Now that I am driving Infopath 2010 and have switched from Java Script to Visual Basic, I feel like I am learning everything from scratch.

    • Firstly, I need the equivalent of the following in VB (Infopath 2007 compatible):

    XDocument.UI.Alert("BlaBlaBla")
    Note: I have not been able to call 'XDocument' at all, as it is not defined.  (I don't recall defining it in JScript). 

    • Secondly, when using the print() command, is there a method to print a specific view?
    • Thirdly, I have a form connection called 'submit' to submit the form to a sharepoint library.  Given that I have not been able to test the form on line yet, is the following method correct?...

    Me.DataConnections("Submit").Execute()

    • Finally, would I be better off using C# rather than VB?

    Regards Phil

Page 1 of 2 (25 items) 1 2 Next >
Copyright © 2003-2018 Qdabra Software. All rights reserved.
View our Terms of Use.