Insert a row in a repeating section based on some condition - InfoPath Dev
in

InfoPath Dev

Insert a row in a repeating section based on some condition

Last post 12-18-2008 08:21 AM by shivajidatta. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 12-17-2008 02:01 PM

    Insert a row in a repeating section based on some condition

    I need to to maintain a changelog and I need soem help with repeating sections to do that.

     

    I need to Insert a row in a repeating section, based on some condition (e.g. when a field is not blank).  So e.g. if I enter text in a blank field, a new row gets automatically added to a repeating section (as if I would have clicked "Insert Item").  

     

    Anybody have any ideas?  My last preference is to code this.

     

    Thanks!

  • 12-17-2008 09:43 PM In reply to

    Re: Insert a row in a repeating section based on some condition

    Hi

    Write code on On after change event.Check the condition, when the condition is true then append a row to the repeating table.

    Look at the below link, it might be helpful in writing the code

    http://aspalliance.com/667_CodeSnip_Add_Row_to_InfoPath_Repeating_Table_on_Button_Click

    Madhuri
    http://www.ggktech.com
  • 12-17-2008 10:18 PM In reply to

    Re: Insert a row in a repeating section based on some condition

    Hi,

    Add an on after change event for the field. And get the repeating node from the sample and add it to the parent group node. The following code will be useful to fulfill your requirement.

    [InfoPathEventHandler(MatchPath = "/my:myFields/my:group6/my:group7/my:field22", EventType = InfoPathEventType.OnAfterChange)]

    public void field22_OnAfterChange(DataDOMEvent e)

    {

    if (e.IsUndoRedo || e.Operation != "Insert" || e.Parent.nodeName != "my:field22")

     {

         return;

     }

     

     if (e.Site.text.Length != 0)

     {               

      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
  • 12-17-2008 11:49 PM In reply to

    Re: Insert a row in a repeating section based on some condition

    Is this in VB Script?
  • 12-17-2008 11:55 PM In reply to

    Re: Insert a row in a repeating section based on some condition

    It is C#.

    Madhuri
    http://www.ggktech.com
  • 12-18-2008 12:24 AM In reply to

    Re: Insert a row in a repeating section based on some condition

    I think my form is set to accept only javascript. Can I write a C# script now that the form is created? I believe the scripting language needs to be specified in the very beginning.. right? I am using IP 2003.
  • 12-18-2008 12:33 AM In reply to

    Re: Insert a row in a repeating section based on some condition

    It is posible to change the code type in your form, but it would require removing any code you already have.  Are you already using JavaScript in the form?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-18-2008 06:57 AM In reply to

    Re: Insert a row in a repeating section based on some condition

    Jimmy:

    It is posible to change the code type in your form, but it would require removing any code you already have.  Are you already using JavaScript in the form?

     

    Hi Jimmy,

     

    Although the form is kind of 80% done, I do not have any code in the form.  How do I change it now?

    Thanks,
    Shivaji

  • 12-18-2008 08:03 AM In reply to

    Re: Insert a row in a repeating section based on some condition

    Just go to Tools->Form Options->Programming, click Remove Code, and select the new code type you want to use.

     Note that only InfoPath 2007 has built-in support for C#, though Swathip's code uses the InfoPath 2003 object model.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-18-2008 08:21 AM In reply to

    Re: Insert a row in a repeating section based on some condition

    In fact I am using InfoPath 2003 myself and I do not have a Tools->Form Options->Programming location in 2003.  I can open up the MS Script Editor from Tools > Programming and clear the code.  But still I do not see any way to select any other scripting language other than JS or VBS.

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