Tuesday, January 19, 2010

Auto Incrementing with InfoPath

So instead of my usual conversation, I thought I'd add a "practical" technical experience I went through because I was not able to find the solution to this particular problem online. If I couldn't find it, perhaps other people out there have had similar issues.

I've been using Microsoft's InfoPath to create a form for Human Resources to do Performance Reviews. Various sections include parts where I wanted to put in a repeating table and although I found ways to "auto increment" an area there to number the entries the user added dynamically, I did not want to use numbers. You see, my sections are numbered and therefore this would just look wrong. It would be much better if my entries were incremented with letters starting with "a".

I wanted my repeating table to look like this:

1. Indicate the primary responsibilities of the position:
a) | User types in section A
b) | User types in section B

So in this table (with two columns, the "a)" is in a column by itself) I set the first "a)" to be an Expression Box. Then you can right click on it and select "Properties". The data source should be "XPath" and set the function to be:

concat(substring("abcdefghijklmnopqrstuvwxyz", position(), 1), ")")

What this function does is concatenate (join) the letter of the alphabet based upon how far down the list you are, and then adds the ")" at the end.

You can make this work with uppercase letters or change the ")" to a "." or whatever you want.

Seems easy once you set it up, but I struggled a bit at first finding where to put this. My programming background came in handy to create the function itself.

Enjoy!

No comments: