Auto-incrementing a field in a table

S

sumeetkbali

Hi,

I have a repeating table and I need to autoincrement one of the fields
whenever the user adds a new row. I have tried the
"count(../preceding-sibiling::*) + 1 " even though I don't exactly get
what it means when it says ../preceding-sibling. Please let me know if
anybody has an idea.

Thanks in advance

Sumeet
 
A

Andrew Watt [MVP - InfoPath]

Hi,

I have a repeating table and I need to autoincrement one of the fields
whenever the user adds a new row. I have tried the
"count(../preceding-sibiling::*) + 1 " even though I don't exactly get
what it means when it says ../preceding-sibling. Please let me know if
anybody has an idea.

Thanks in advance

Sumeet

Sumeet,

If I correctly understand what you are doing then
count(../preceding-sibling::*)+1
should work.

The XPath formula .. selects parent nodes. The preceding-sibling::*
selects all preceding siblings of those parent nodes whatever the name
of those nodes. If you want the count to start at 1 then you add one
to the value that the count() function returns.

Andrew Watt
MVP - InfoPath
 
K

KingFu

Hi Andrew,

I've got a similar problem. I have a form that contains questions/answers.
On one of the questions, you could have multiple answers. My HR Dept wants
me to label these answers as (if you were on question 12)
12 a.
12 b.
12 c.
12 d. etc...

I've tried the "count(../preceding-sibiling::*) + 1" and get an error --

The axis is not valid.
count(../-->preceding-sibiling<--::*) + 1

My data source looks similar to this:

myFields
group1
group2
answer to question 12
comments
I'm putting the expression box in group2 for the abc or 123 count of rows.

Does this make sense? Can you help me out?
 
B

Bali

Hi,

I was getting the same error so what I did was make the formula just
count(preceding-sibling::*)+1 instead of
count(../preceding-sibling::*)+1.

If you click the edit x-path checkbox below it in the case of
count(preceding-sibling::*)+1 it shows it as
count(../preceding-sibling::*)+1. As Andrew explained thats what we
want but in case of count(../preceding-sibling::*)+1 is written in the
formula field and you click edit x-path then the formula appears as
count(../../preceding-sibling::*)+1.

I don't know how you would take care of the 12 a, 12 b stuff but the
auto numbering worked this way

Sumeet
 
K

KingFu

Thanks! That fixed it. At least I'll be able to do a 12.1, 12.2, 12.3
etc.... hopefully that will suffice, as I think the alphabet solution would
be very problematic.

Thanks again,

KingFu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top