Automatically insert rows into repeating section - InfoPath Dev
in

InfoPath Dev

Automatically insert rows into repeating section

Last post 09-09-2010 01:00 PM by Patrick Halstead. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 12-07-2005 03:22 PM

    Automatically insert rows into repeating section

    Hi there,

    I'm developing a form and have come to a problem. Instead a repeating section, I want the users to be only able to enter values into three set fields for the same table.

    To give you an example, I have a table where users can enter the number of a particular type of fruit that they'd like to order. I have only three types of fruit. I want them to have to enter a number for each type of fruit, instead of making the field a repeating section.

    Instead of:
    ------------------------------------------
    FruitType Number
    [drop-down containing fruit types] [*]
    Insert new FruitType
    ------------------------------------------


    I want:
    ------------------------------------------
    FruitType Number
    Orange *
    Apple *
    Pear *
    ------------------------------------------

    Is this possible at all?

    Thanks,
    Chris
  • 12-07-2005 05:36 PM In reply to

    Re: Automatically insert rows into repeating section

    I must be oversimplifying this... Use a regular section (instead of repeating) or even no section at all and put three textboxes beside the three fruits. The textboxes will default to zero and the user can change each one (data validation would be num >= 0). If you play around with the way the textboxes look you could get them to look however you want.

    ------------------------------------------
    FruitType Number
    Orange [numOrange textbox default=0 datatype=integer]
    Apple [numApple textbox default=0 datatype=integer]
    Pear [numPear textbox default=0 datatype=integer]
    ------------------------------------------

    Hope this helps!

    ---------------
    Matt Faus
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 12-11-2005 06:42 PM In reply to

    Re: Automatically insert rows into repeating section

    That's what I'm hoping to get to, but the reason why I started on a repeating section is because these will end up as specific rows withing a database table. (Sorry, I just realized that I didn't mention this in the first post.) The schema of this table will look like:

    [CustomerID (int) | FruitType (int) | OrderAmount (int)]

    You can see how I would naturally end up with a repeating section based on this table's schema, but I want to force insert 3 rows into this table with different FruitTypes.

    I've tried playing around with your suggestion, but Infopath will map the text-boxes to the same data element. Whenever I type a number into one text-box it will replicate the result to the other two.

    Thanks,
    Chris
  • 12-13-2005 09:41 AM In reply to

    • Stavi
    • Top 100 Contributor
    • Joined on 12-13-2005
    • Posts 95

    Re: Automatically insert rows into repeating section

    Use the repeating table you have and 4 regular fields, CustId, NoOranges, NoApples, NoPears

    When the user has filled in the form and saves, closes or what ever, use this script to create 3 rows in the repeating table.

    // get values
    IXMLDOMNode CustID = thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:MyFields/@CustID");
    IXMLDOMNode NoOranges = thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:MyFields/@Oranges");
    IXMLDOMNode NoApples = thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:MyFields/@Apples");
    IXMLDOMNode NoPears = thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:MyFields/@Pears");

    // get a reference to the node the repeating table is bound to
    IXMLDOMNode row = thisXDocument.DOM.selectSingleNode("//d:repeatingtable1");
    // make a copy of the node by cloning it
    row = row.cloneNode(true);

    // set the new values of the row#%92s fields for Oranges
    row.selectSingleNode("@RepeatingTableID").text = "";
    row.selectSingleNode("@CustID").text = CustID.text;
    row.selectSingleNode("@Type").text = "1";
    row.selectSingleNode("@Number").text = NoOranges.text;
    // append the cloned row to the parent node
    IXMLDOMNode parent = thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields");
    parent.appendChild(row);

    // set the new values of the row#%92s fields for Apples
    row.selectSingleNode("@RepeatingTableID").text = "";
    row.selectSingleNode("@CustID").text = CustID.text;
    row.selectSingleNode("@Type").text = "2";
    row.selectSingleNode("@Number").text = NoApples.text;
    // append the cloned row to the parent node
    IXMLDOMNode parent = thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields");
    parent.appendChild(row);

    // set the new values of the row#%92s fields for Pears
    row.selectSingleNode("@RepeatingTableID").text = "";
    row.selectSingleNode("@CustID").text = CustID.text;
    row.selectSingleNode("@Type").text = "3";
    row.selectSingleNode("@Number").text = NoPears.text;
    // append the cloned row to the parent node
    IXMLDOMNode parent = thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields");
    parent.appendChild(row);

    Ok, this worked for me after lots of tidying up on one of my forms. Also you'll have to put in the first row straight into the database as this can only clone and paster rows not create them.

    I posted this in a rush, ask if i did something silly
  • 12-14-2005 06:55 PM In reply to

    Re: Automatically insert rows into repeating section

    quote:
    Originally posted by Stavi

    Use the repeating table you have and 4 regular fields, CustId, NoOranges, NoApples, NoPears

    When the user has filled in the form and saves, closes or what ever, use this script to create 3 rows in the repeating table.

    ...

    Ok, this worked for me after lots of tidying up on one of my forms. Also you'll have to put in the first row straight into the database as this can only clone and paster rows not create them.

    I posted this in a rush, ask if i did something silly



    Thanks for the help Stavi! I'll give it a try.
  • 05-13-2008 06:36 AM In reply to

    • Bill
    • Top 200 Contributor
      Male
    • Joined on 09-26-2006
    • USA
    • Posts 57

    Re: Automatically insert rows into repeating section

    Hi Stavi,

    I mofied the code in the example given.  Here is my code

    Dim newVal1 As String

    Dim row, parent As MSXML.IXMLDOMNode

    If thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:App1171/@A174Q15a1").text = "Y" Then

    thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:App1171/d:DHS1171_Application/d:DHS1171_HouseholdMember/d:DHS1171_OtherIncomes/@IncomeSourceType").text = "RSDI"

    newVal1 = thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:App1171/d:DHS1171_Application/d:DHS1171_HouseholdMember/d:DHS1171_OtherIncomes/@IncomeSourceType").text

    'get a reference to the node the repeating table is bound to

    row = thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:App1171/d:DHS1171_Application/d:DHS1171_HouseholdMember/d:DHS1171_OtherIncomes/")

    'make a copy of the node by cloning it

    row = row.cloneNode(True)

    'set the new values

    row.selectSingleNode("/dfs:myFields/dfs:dataFields/d:App1171/d:DHS1171_Application/d:DHS1171_HouseholdMember/d:DHS1171_OtherIncomes/@IncomeSourceType").text = "Select..."

    'append the cloned row to the parent node

    parent = thisXDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:App1171/d:DHS1171_Application/d:DHS1171_HouseholdMember")

    parent.appendChild(row)

    End If

    It makes it thru the clone process w/o any errors but I never see the new row on my form.  Can someone please tell me what I am doing wrong.

     

    Thanks! 

     

    William L Fringer
    Database Administrator/Systems Integration Specialists

    L & S Associates, Inc.
    Michigan State University Corporate Research Park

    1-800-766-6185, ext 2076
  • 04-08-2009 09:21 PM In reply to

    Re: Automatically insert rows into repeating section

    hi,

    I am using infoPath 2007, i need to insert rows in to repeating section.

    I am having only xmlNavigator. I have one repeater section which contain two text boxs.

    I need to add the value at run time. no of section are known only at run time.

    Can any help to add new row inside the repeating section.

  • 04-10-2009 08:40 AM In reply to

    Re: Automatically insert rows into repeating section

    Hi:

    What does your code look like thus far? How do you know how many new rows you need to add? Is this based on another data connection, or something the user enters?

    Hilary Stoupa

  • 04-14-2009 09:08 PM In reply to

    Re: Automatically insert rows into repeating section

    Hi,

     i am using web service as data source. It will return the dataset. based on the no of rows in datatable, i have to create the repeater section. I also have to provide the user with option for inserting new fields in the repeating section and updatind the existing fields. Newly inserted fields informations are submited to the Database using web service.

    So can you help me to achieve this.

     

    Thanks,

  • 09-09-2010 01:00 PM In reply to

    Re: Automatically insert rows into repeating section

    Hi Skumar38,

    Here's a new document that describes how to do this with qRules v2.2

    http://www.infopathdev.com/files/folders/qrules/entry58577.aspx

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