Simple Code to Add Row - InfoPath Dev Sign in | Join | Help in Code InfoPath (Entire Site) InfoPath Dev InfoPath Dev is dedicated to bringing you the information and tools you need to be successful in your Microsoft Office InfoPath development projects. Home Blogs Forums Photos Downloads InfoPath Dev » InfoPath » Code » Simple Code to Add Row 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: Oldest to newest Newest to oldest Previous Next 07-08-2008 08:43 AM PJagger Joined on 11-20-2007 Australia Posts 40 Simple Code to Add Row Reply Contact 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: JScript, 2007, script 07-08-2008 03:51 PM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Simple Code to Add Row Mark as Not AnswerMark as Answer... Reply Contact 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 Joined on 11-20-2007 Australia Posts 40 Re: Simple Code to Add Row Mark as Not AnswerMark as Answer... Reply Contact 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 Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Simple Code to Add Row Mark as Not AnswerMark as Answer... Reply Contact 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 Joined on 11-20-2007 Australia Posts 40 Re: Simple Code to Add Row Mark as Not AnswerMark as Answer... Reply Contact You got it Hilary Regards - Phil 07-11-2008 07:48 AM In reply to Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Simple Code to Add Row Mark as Not AnswerMark as Answer... Reply Contact 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 Joined on 11-20-2007 Australia Posts 40 Re: Simple Code to Add Row Mark as Not AnswerMark as Answer... Reply Contact 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 Hilary Stoupa Joined on 06-20-2008 Posts 13,297 Re: Simple Code to Add Row Mark as Not AnswerMark as Answer... Reply Contact 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 Joined on 11-20-2007 Australia Posts 40 Re: Simple Code to Add Row Mark as Not AnswerMark as Answer... Reply Contact 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 Joined on 02-27-2009 Minneapolis Posts 22 Re: Simple Code to Add Row Mark as Not AnswerMark as Answer... Reply Contact 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 Jimmy Joined on 07-03-2008 Posts 2,595 Re: Simple Code to Add Row Mark as Not AnswerMark as Answer... Reply Contact 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 MVPQdabra Software 12-02-2010 01:35 AM In reply to PJagger Joined on 11-20-2007 Australia Posts 40 Re: Simple Code to Add Row Mark as Not AnswerMark as Answer... Reply Contact 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 Jimmy Joined on 07-03-2008 Posts 2,595 Re: Simple Code to Add Row Mark as Not AnswerMark as Answer... Reply Contact 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 MVPQdabra Software 12-03-2010 03:41 AM In reply to PJagger Joined on 11-20-2007 Australia Posts 40 Re: Simple Code to Add Row Mark as Not AnswerMark as Answer... Reply Contact Thank you! 12-07-2010 04:31 AM In reply to PJagger Joined on 11-20-2007 Australia Posts 40 Re: Simple Code to Add Row Mark as Not AnswerMark as Answer... Reply Contact 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-2019 Qdabra Software. All rights reserved.View our Terms of Use.
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
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?
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
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?
You got it Hilary
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.
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'.
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.
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.
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.
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");
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?
Appreciate all your help
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
Thank you!
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.
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).
Me.DataConnections("Submit").Execute()