Repeating Table – set color for alternative rows and auto number the rows

Set color for alternative rows:

Logic behind : Odd number of rows(1,3,5,7..) when divided by 2 will return the remainder 1  and even number of rows(2,4,6,8..) when divided by 2 will return the remainder 0. To find the remainder, we use mod(modulo) operator. To find whether the row is odd number or even number, we can use position() in infopath.

  • Go to Home->Manage rules
  • In fields pane, select the group containing repeating fields and add formatting rule
  • Under condition, click on None and select “The expression” in first drop down
  • To color the odd rows, enter the expression as position() mod 2 > 0 or position() mod 2 = 1
  • Under Formatting, select the color that you would like to apply in Shading(bucket symbol)

Color alternative rows

  • Click on Home->Preview to see the result

Auto number repeating table rows:

  • To auto generate number in SNO inside repeating table, right click on SNO ->Text Box Properties
  • Under Default values, click on fx and insert the formula, count(../preceding-sibling::my:group2) + 1 and click ok

  • You can also use position() instead of the above formula but this will not be supported in InfoPath 2013 text box. However, it can be used in Calculated value in InfoPath 2013. Right click the SNO ->Change Control->Calculated Value and enter position() in XPath

  • Click on Home -> Preview to see the result.



Repeating Table – Set default number of rows and limit the total number of rows

Repeating table plays a vital role in form library to insert several rows of data in a single form. In this post, let’s see two different methods of setting the default number of rows and limiting the total number of rows in repeating table.

METHOD 1 – Using Default Values and Rules

Set default number of rows:

  • Go to Data tab in the ribbon and click on Default Values
  • In Edit Default values dialog box, right click on group that contains the repeating table fields and select “Add another group below”. Repeat this step to increase the default number of rows
  • Click on Home->Preview to see the result.

  • Limitation – You will not be able to remove the rows inserted by this method

Limit total number of rows:

  • Go to Home tab and click on Manage rules
  • Select the group(group2 in above picture) that contains repeating fields in Fields pane
  • In Rules pane, click on New -> Formatting
  • Under condition, select “The expression” in first drop down, type the expression value as count(/my:myFields/my:group1/my:group2) = 6
  • Under Formatting, tick the box “Don’t allow users to insert or delete this control” as depicted below

  • Now, when the user inserts the 6th row and click on insert item, rows will not be created and drop down highlighted below shown till 5th row will disappear on inserting 6th row to prevent insertion and deletion.

METHOD 2: (Modifying the Source File)

  • After designing the form with repeating table, click on Publish -> Export Source Files

  • Browse the location and type the folder name to save the source file

  • Close the InfoPath form and open “myschema.xsd” from source file folder

  • To set default number of rows, change the minOccurs value as shown below
  • To limit the total number of rows, change the maxOccurs value as shown below

  • Save myschema.xsd and close it
  • Open manifest file in Design mode, preview and publish it
  • Now, when the user tries to insert 11th row, below error will be shown.