Insert Blank Rows to Repeating Table - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Insert Blank Rows to Repeating Table

Last post 02-11-2015 11:01 AM by JonesAF. 18 replies.
Page 1 of 2 (19 items) 1 2 Next >
Sort Posts: Previous Next
  • 06-28-2009 09:59 PM

    Insert Blank Rows to Repeating Table

    Hi Everyone,

    I want to have a new blank row be inserted into a repeating table automatically, for example:

    The form loads and if the single data source in the repeating table is NOT blank, then I want a new row to be inserted automatically.

    So the condition is If DataSource in not blank, then insert new row with blank data source.

    I would imagine it would happen in the "Open and Save" Form Options, but it is not obvious to me how to do it.

    I hope this makes sense :)

    Thanks in advance

  • 06-28-2009 10:08 PM In reply to

    Re: Insert Blank Rows to Repeating Table

    Hi,

    In the onload check the condition and if that condition is satisfied then add the below code.

     

      IXMLDOMDocument2 sampleDataDom = (IXMLDOMDocument2)thisXDocument.CreateDOM();

     sampleDataDom.setProperty("SelectionNamespaces", "your form name space");

     sampleDataDom.load("sampledata.xml");

     IXMLDOMNode sampleGroupNode = sampleDataDom.selectSingleNode("/my:myFields/my:group6/my:group7");

     

     IXMLDOMNode parentNode = thisXDocument.DOM.selectSingleNode("/my:myFields/my:group6");

     parentNode.appendChild(sampleGroupNode);

     

    Here "/my:myFields/my:group6/my:group7 -> is the repeating section xpath

    /my:myFields/my:group6/my:group7/my:field22 -> repeating section field xpath

    Swathip
    www.ggktech.com
  • 06-28-2009 10:30 PM In reply to

    Re: Insert Blank Rows to Repeating Table

    Sorry for the Noob Question, but how do I enter the code?

    If I go Tools/Form Options - select "Open and Save", then click on the rules button, I have access to where I can set conditions and actions I want met when I open the form.

    I can set the condition fine by then clicking "Add" and "Set Condition", but I am unsure how to insert the code.

    Do I simply add the code to the "Value"  field where I would normally add actions and functions?

    More Noob questions ...

    Can you please define what data I need to put in place of this code:
    - IXMLDOMDocument
    - sampleDataDom
    - SelectionNamespaces
    - your form name space
    - sampledata.xml

    Also will this code work in a browser based form?

    Thanks in advance.

  • 06-28-2009 10:42 PM In reply to

    Re: Insert Blank Rows to Repeating Table

    Hi,

     

    Once go through the below link to know how to add the code.

    http://www.infopathdev.com/forums/p/10129/36055.aspx#36055

    Swathip
    www.ggktech.com
  • 06-29-2009 03:55 PM In reply to

    Re: Insert Blank Rows to Repeating Table

    Thanks for your help so far swathip, I think I am getting out of my depth here.

    I read the link you sent, and it outlines how to add a row to a repeating table by clicking a button, but I want it to happen when the form loads.

    I have installed Microsoft Visual Studio Tools for Applications and I can access that if I go to the Tools/Programing/Loading Event ... Menu item, and the VSTA loads and my eyes glaze over and I am lost.

    Am I close and on the right track?

    The code that appears when VSTA loads is below:

     

    using Microsoft.Office.InfoPath;
    using System;
    using System.Xml;
    using System.Xml.XPath;

    namespace IT_Job_Requests_2_1_Change_to_C_
    {
        public partial 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 object _memberVariable
            // {
            //     get
            //     {
            //         return FormState["_memberVariable"];
            //     }
            //     set
            //     {
            //         FormState["_memberVariable"] = value;
            //     }
            // }

            // NOTE: The following procedure is required by Microsoft Office InfoPath.
            // It can be modified using Microsoft Office InfoPath.
            public void InternalStartup()
            {
                EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
            }

            public void FormEvents_Loading(object sender, LoadingEventArgs e)
            {
                // Write your code here.
            }
        }
    }

     

    I am assumeing I should try and insert  the code you wrote at ther bottom where the comment says "Write your code here" ...

    Fingers crossed ...

  • 06-29-2009 04:07 PM In reply to

    Re: Insert Blank Rows to Repeating Table

    I have inserted your code, and I get several errors that I do not understand.

    Code 

    Am I even close?  I am really out of my depth here.

    Thanks in advance.

  • 06-29-2009 04:11 PM In reply to

    Re: Insert Blank Rows to Repeating Table

    You have been provided with an InfoPath 2003 object model code sample. Your form is set to use InfoPath 2007. Under Tools / Form Options / Programming you can change your programming language. Since this sample is C# for 2003, you can select that from the drop down for the language.

    Hilary Stoupa

  • 06-29-2009 06:50 PM In reply to

    Re: Insert Blank Rows to Repeating Table

     Hi Hilary,

    Thanks for the clarification.  My Form is browser-enabled, and when I go to Tools / Form Options / Programming only get 2 options in the drop down box, C# and Visual Basic.

    I also get a message saying "Script and depreciated object models are not supported in browser-enabled form templates".

    I am assuming that I cannot use this C# for 2003 code sample provided above because my form template is browser-enabled?  DAMN!

    Does anyonme have any other suggestions that would help me please?

    Thanks in advance.

  • 06-29-2009 07:44 PM In reply to

    Re: Insert Blank Rows to Repeating Table

    Mars, this is just a guess, but you can browser-enable a 2007-based form that is saves as a 2003 file.  You can't do this from 2003, but you can do it from 2007.  Maybe try doing a Save As on your template and choose the InfoPath 2003 format.  Then, go back into the Programming settings to see if that 2003 option is there.

  • 06-29-2009 08:00 PM In reply to

    Re: Insert Blank Rows to Repeating Table

    Thanks for the idea,

    I tried it and I lost the use of the ()username function, plus when I tried to open open Visual Studio Tools for Applications it made me change back to version 2007 anyway ...

    It seems I need version 2007 compatible code.

    Is there not an easier way to do this?  It seems allot of trouble just to add another row to a repeating table :(

    Thanks.

  • 06-29-2009 08:07 PM In reply to

    Re: Insert Blank Rows to Repeating Table

    It does seem like it would be pretty simple, but I just don't know of a way.

  • 06-30-2009 09:06 AM In reply to

    Re: Insert Blank Rows to Repeating Table

    Hi -- here's C# for 2007:

            public void FormEvents_Loading(object sender, LoadingEventArgs e)
            {
                //get your repeating group. The XPath in quotes needs to change according to your form's data structure
                //you want to add a new row only if there is no completely blank row available, so we will filter our XPath to only select a group where all the fields are blank
                //my group only has two fields. Yours may be different. You'll need to change the bit in the square brackets to address your data structure
                XPathNavigator parent = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:topGroup", NamespaceManager);
                XPathNavigator group = parent.SelectSingleNode("my:repeatingGroup[my:rgField1 = '' and my:rgField2 = '']", NamespaceManager);
     
                //if our variable group is null, we have no 'empty' rows in our form and need to add one
                if (null == group)
                {
                    //get our repeating group from sampledata.xml
                    XmlDocument sample = new XmlDocument();
                    sample.Load(this.Template.OpenFileFromPackage("sampledata.xml"));
     
                    XPathNavigator newGroup = sample.CreateNavigator().SelectSingleNode("/my:myFields/my:topGroup/my:repeatingGroup", NamespaceManager);
     
                    parent.AppendChild(newGroup);
     
                }
     
            }
    Hilary Stoupa

  • 06-30-2009 06:30 PM In reply to

    Re: Insert Blank Rows to Repeating Table

     Hi Hilary, thank you for your help :)

    Apologies for the Noob Question, but code gives me a headache and I really don't know how to enter the references to my data source in the square brackets as you have mentioned in the comments of your code.

    Can you please re-post the code so that it will work with my data sources below:

    Data Source The Repeating table group is called "Group 7", and the field in question is "TechnicianComments".

    Thanks in advance.

  • 07-01-2009 03:42 PM In reply to

    Re: Insert Blank Rows to Repeating Table

    So, if Technician Comments is blank, you want to add a new row?

            public void FormEvents_Loading(object sender, LoadingEventArgs e)
            {
                //get your repeating group. The XPath in quotes needs to change according to your form's data structure
                //you want to add a new row only if there is no completely blank row available, so we will filter our XPath to only select a group where all the fields are blank
                //my group only has two fields. Yours may be different. You'll need to change the bit in the square brackets to address your data structure
                XPathNavigator parent = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:TechnicianPage/my:TechComments", NamespaceManager);
                XPathNavigator group = parent.SelectSingleNode("my:group7[my:TechnicianComments = '']", NamespaceManager);
     
                //if our variable group is null, we have no 'empty' rows in our form and need to add one
                if (null == group)
                {
                    //get our repeating group from sampledata.xml
                    XmlDocument sample = new XmlDocument();
                    sample.Load(this.Template.OpenFileFromPackage("sampledata.xml"));
     
                    XPathNavigator newGroup = sample.CreateNavigator().SelectSingleNode("/my:myFields/my:TechnicianPage/my:TechComments/my:group7", NamespaceManager);
     
                    parent.AppendChild(newGroup);
     
                }
     
            }

    Hopefully I don't have any typos in the XPaths and this will just work for you.

    Hilary Stoupa

  • 07-01-2009 07:56 PM In reply to

    Re: Insert Blank Rows to Repeating Table

    Fantastic!  Thank you so much!

    I had some trouble publishing the form template, but I found a half decent and reasonably easy to understand description here: 

    http://blogs.interknowlogy.com/jeffschroeder/archive/2006/10/31/7913.aspx

    Weird that such a simple thing like "insert a new row if data source is empty" is so hard to make happen ...

    As a side note, I found in Tools / Options / Design an option "Programming language when designing forms in infopath:", where I could change it from C# to C# (Infopath 2003 Compatible). Changing this may have made my form accept the original 2003 code posted above, but I have not tested this ... Now that My form is working I'm not touching it!

    Thanks again.

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