locked
Automatically number a repeating table RRS feed

  • Question

  • I have a section within a form template that contains a repeating table. The table has a column called "Line Number." I want the default value for the first line to be "1" and for each row that is added in the repeating table, I want that value to increase by "1".

    Basically, I would have something like this (inside the parenthesis represents the function that would occur):

    Line Number
    1=(1)
    2=(1+1)
    3=(2+1)
    4=(3+1)
    5=(4+1)
    6=(5+1)

    Is anyone aware of how I can do this? Thank you for your help in advance.
    Thursday, May 28, 2009 12:52 PM

Answers

  • Assign initial value of the field to the formula: count(/my:myFields/my:YourRepeatingGroupName) Also uncheck "Update this value when the result is recalculated" checkbox.

    http://alecpojidaev.wordpress.com
    • Proposed as answer by Clayton Cobb Thursday, May 28, 2009 4:03 PM
    • Marked as answer by SP Brian Thursday, May 28, 2009 4:27 PM
    Thursday, May 28, 2009 3:33 PM

All replies

  • Hi Brian,

    Unfortunately there is no event available when you click insert item as far as i know, the workaround could be when any field in the repeating table row lost focus it fires changed event,  you can check the LineNumber field and if empty, set LineNumber = previous line number value + 1






    Regards
    Ashraf ul Islam
    Sharepoint Consultant



    Thursday, May 28, 2009 1:30 PM
  • Would I have to do this programmatically? I am not familiar with the coding behind InfoPath. Is there a way I can do it on the graphical interface? If so, could you describe that process please?

    Thank you for your help.

    Brian
    Thursday, May 28, 2009 3:19 PM
  • Assign initial value of the field to the formula: count(/my:myFields/my:YourRepeatingGroupName) Also uncheck "Update this value when the result is recalculated" checkbox.

    http://alecpojidaev.wordpress.com
    • Proposed as answer by Clayton Cobb Thursday, May 28, 2009 4:03 PM
    • Marked as answer by SP Brian Thursday, May 28, 2009 4:27 PM
    Thursday, May 28, 2009 3:33 PM
  • I am actually not sure how to do that. Do I have to go into the XML and perform this? It appears that way. I just do not have any experience doing this. How do I access the XML to edit it?
    Thursday, May 28, 2009 3:41 PM
  • Assign initial value of the field to the formula: count(/my:myFields/my:YourRepeatingGroupName) Also uncheck "Update this value when the result is recalculated" checkbox.

    http://alecpojidaev.wordpress.com

    Alec, this works when I just tested it, but why did I have to physically type in the path as opposed to selecting my repeating group using the count function GUI?  What it looked like was count(..), and that just gave a 1 for each new item.  When I went in and typed count(/my:myFields/my:Group/my:RepeatingGroup), it showed up as count(Groups) and worked like a charm.  How is that Xpath different from count(..) when they point to the same thing?
    SharePoint Architect - Planet Technologies - 4-Year Microsoft Federal Partner of the Year (2005-2008)
    Thursday, May 28, 2009 3:43 PM
  • To: SP_Brian
    You just have to double click at the field you want to be a counter then the form will pop up. In that form there is section called Default Value. Press Fx button then edit XPath (advanced) check box.
    http://alecpojidaev.wordpress.com
    Thursday, May 28, 2009 3:51 PM
  • To: Clayton Cobb
    Because when you are using relative XPath it will point to the single (parent of the current) node. Typing absolute XPath is letting know to the engine that you are interested in collection of nodes.


    http://alecpojidaev.wordpress.com
    Thursday, May 28, 2009 3:55 PM
  • I went into the default value of the field in which I wanted the incremental value. I clicked the function button, checked edit xpath, enter the formula "count(/my:myFields/my:quote_product_info_data)" and it returns the error:

    "/my:myFields/my:quote_product_info_data" does not point to a valid location path of a field or group.

    http://img39.imageshack.us/img39/6389/datasource.jpg

    Please view the image to see what I have for my data sources.
    Thursday, May 28, 2009 4:15 PM
  • Is "quote_product_info_data" the name of your repeating GROUP from which you created the repeating table?  I tested the concept, and it worked perfectly when using the proper Xpath code. 

    Oh, based on your screenshot, your Xpath is wrong, because you have your repeating group embedded deep within 2 other groups, which have to be accounted for in your Xpath.  Here is the correct Xpath, I believe:

    count(/my:myFields/my:quoted_product_info/my:quote_product_info_repeat_table/my:quote_product_info_data)


    SharePoint Architect - Planet Technologies - 4-Year Microsoft Federal Partner of the Year (2005-2008)
    Thursday, May 28, 2009 4:23 PM
  • Hi Alec & Clayton Cobb,

    If i apply Count(/my:myFields/my:group1/my:group2) formula to the field in repeating table i get following output

    Line Number
    3
    3
    3

    as oppose to

    Line Number
    1
    2
    3


    How it is working with you ?


    Thursday, May 28, 2009 4:25 PM
  • Uncheck "Update this value when the result is recalculated" checkbox.

    From Alec above...
    SharePoint Architect - Planet Technologies - 4-Year Microsoft Federal Partner of the Year (2005-2008)
    Thursday, May 28, 2009 4:28 PM
  • The XPath that you gave me worked perfectly. Thank you both for your help. It is hard for me to answer your question because I do not understand the data source piece of InfoPath completely.

    I actually played around with the data sources and came up with this:

    http://img39.imageshack.us/img39/826/datasourcei.jpg

    then set the default value to count(quote_product_info_data) which also works.
    Thursday, May 28, 2009 4:34 PM
  • The Xpath I gave you eventually resolves to count(quote_product_info_data), so that's why that works for you.

    Brian, one thing to remember is that you are referring to your data elements as data sources, which is confusing.  The entire set of elements is your main data source, and any other data connections you create would be considered secondary data sources.  Don't refer to the individual groups and fields as data sources, and then it should make more sense.


    SharePoint Architect - Planet Technologies - 4-Year Microsoft Federal Partner of the Year (2005-2008)
    Thursday, May 28, 2009 4:47 PM
  • Thank you. I will keep that in mind for the future.
    Thursday, May 28, 2009 4:52 PM