Repeating Tables: Dynamic number of default rows. - InfoPath Dev
in

InfoPath Dev

Repeating Tables: Dynamic number of default rows.

Last post 01-19-2009 08:46 AM by mocathe1st. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-19-2009 04:02 AM

    Repeating Tables: Dynamic number of default rows.

    Hi all,

    I'm currently working on an Infopath 2007 form based on my own XML Schema where some form elements have repeating tables which should have a default number of rows based on a value in another section of the form. I had thought that this may be possible using an XPath query in the default values properties for the Repeating Table, but cannot find a way of inserting the query.

    My form is part of a solution for gathering data to be inserted into a simulation environment. What I'm trying to do here is to allow the user to insert the x number of timesteps in the simulation and then have x number of entries in the relevant repeating tables (one for each timestep).

    I'm not very experienced with Infopath and can't find a way of doing this. I suspect that I may need to write some JScript macros or something, but had hoped that there is an easier, XPath based, way of doing this.

    Any help would be most appreciated.

    Malcolm.

  • 01-19-2009 05:40 AM In reply to

    Re: Repeating Tables: Dynamic number of default rows.

    Hi,

    You can restrict the number rows in a repeating table using the following code in C#.

    public void group6_Changing(object sender, XmlChangingEventArgs e)

    {

    XPathNavigator xn = this.MainDataSource.CreateNavigator(); XmlNamespaceManager xnsm = new XmlNamespaceManager(new NameTable()); xnsm.AddNamespace("my", "<Name space of the form>");

    XPathNodeIterator nodeIterator = xn.Select("/my:myFields/my:group5/my:group6", xnsm);

    int count = 2;

     if(nodeIterator.Count > count)         

     {

      e.CancelableArgs.Cancel = true;

      return;

    }

    }

     

    Here "/my:myFields/my:group5/my:group6" is the repeating table xpath. and

    Count is the number of rows you want to restrict after.

     Note: After this it will show a error message.

              

    Swathip
    www.ggktech.com
  • 01-19-2009 06:03 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Repeating Tables: Dynamic number of default rows.

    Hello,

    Here is the code,

    function msoxd_my_group2::OnBeforeChange(eventObj)

    {

    var node = XDocument.DOM.selectSingleNode("/my:myFields/my:field2").text;

    var groupNode = XDocument.DOM.selectSingleNode("/my:myFields/my:group1");

     //repeating node is group2

    var count = groupNode.selectNodes("my:group2").length;

    if(count > node)

    {

    eventObj.ReturnStatus = false;

    }

    }

  • 01-19-2009 08:46 AM In reply to

    Re: Repeating Tables: Dynamic number of default rows.

     Hi,

     Thanks for that.The restriction is pretty useful and I will be using that but what I was really looking for was a way of having the rows already exist in the form based on the number of time steps.

    e.g. if I had 24 timesteps defined e.g. in /TimeSteps/@number then I would like to have 24 empty rows displaying when a (relevant) element with a repeating table is added to the form (e.g. from a choice of elements)

     I've got the element choice nailed, but what I can't figure out is how to add a default number of rows based on the timesteps. The only way I can come close to this is to set the minOccurs for the element in the schema to something but I can't find a dynamic way of doing this. From what I can see you cannot use XPath in XSD schemas.

     I hope that is clear. I think what I'm trying to do is possibly a little too complex, but I can't think of a better way of doing it.

    Thanks for your help and any ideas on how to do the above would be appreciated.

    Malcolm

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