Setting Default Values Between Repeating Sections

J

Janie

In XPath, how can I say, "go to field1 in the previous repeating section and
return the value in field2 of this repeating section?" I'm trying to do this
with a rule that actions when a new repeating section is made, but the value
in the very first field1 occurs in all field2s in all subsequent repeating
sections. I feel like my indexing isn't right...field2's function seems like
it would be as easy as something like
/my:form/my:repeatingSection/field1[position()-1], but I haven't been able to
get it.

I've tried giving this a go in js (from a previous suggestion), but am only
teaching myself js now, so am having difficulty with this as well...am a bit
new to xpath too.

Any suggestions greatly appreciated...
 
A

Andrew Watt [MVP - InfoPath]

In XPath, how can I say, "go to field1 in the previous repeating section and
return the value in field2 of this repeating section?" I'm trying to do this
with a rule that actions when a new repeating section is made, but the value
in the very first field1 occurs in all field2s in all subsequent repeating
sections. I feel like my indexing isn't right...field2's function seems like
it would be as easy as something like
/my:form/my:repeatingSection/field1[position()-1], but I haven't been able to
get it.

I've tried giving this a go in js (from a previous suggestion), but am only
teaching myself js now, so am having difficulty with this as well...am a bit
new to xpath too.

Any suggestions greatly appreciated...

Janie,

If you have SP1 an easy way to explore this is to create the form
template that you want then drag an expression box to the design
surface, then click on fx in the dialog window that opens.

Then in the next dialog click on Insert Field or Group. Choose the
field or group you want then check the Edit XPath checkbox and you
will see the full XPath expression.

Looking at your formula you probably want to have the predicate on the
section not the field.

Something like
/my:form/my:repeatingSection[1]/field1
as the default value for field2 should be close to what you want.

Andrew Watt
MVP - InfoPath
 
J

Janie

Andrew Watt said:
In XPath, how can I say, "go to field1 in the previous repeating section and
return the value in field2 of this repeating section?" I'm trying to do this
with a rule that actions when a new repeating section is made, but the value
in the very first field1 occurs in all field2s in all subsequent repeating
sections. I feel like my indexing isn't right...field2's function seems like
it would be as easy as something like
/my:form/my:repeatingSection/field1[position()-1], but I haven't been able to
get it.

I've tried giving this a go in js (from a previous suggestion), but am only
teaching myself js now, so am having difficulty with this as well...am a bit
new to xpath too.

Any suggestions greatly appreciated...

Janie,

If you have SP1 an easy way to explore this is to create the form
template that you want then drag an expression box to the design
surface, then click on fx in the dialog window that opens.

Then in the next dialog click on Insert Field or Group. Choose the
field or group you want then check the Edit XPath checkbox and you
will see the full XPath expression.

Looking at your formula you probably want to have the predicate on the
section not the field.

Something like
/my:form/my:repeatingSection[1]/field1
as the default value for field2 should be close to what you want.

Andrew Watt
MVP - InfoPath

Great, you were right about the predicate. But I'm having difficulty with
what goes in it: /my:form/my:repeatingSection[???]/field1
I thought it should be a function like position() it because it will
increment with each new repeating section, but it behaves just like puttin a
1 in the predicate.

So, I need a way to get this incrementing to happen when the rule is set of
by creating a new repeating section. It does work for any number in place of
the 1, so the problem must be in the the function bit. What do ya reckon?
Thanks...
 
J

Janie

Greg Collins said:
Janie,

The answer is very difficult to discover without a good knowledge of XPath. I was attempting to do the same thing at one point and it took quite a lot of playing to come up with an XPath expression that actually works.

The following will work on a repeating table or section to go from the current row to the preceding row and get a value. You may need to massage it into your particular application.

.../my:repeatingSection[count(current()/preceding-sibling::my:repeatingSection)]/@my:field1

What this does is first gets the count of all the preceding siblings of "my:repeatingSection" starting from current() which gives you a number equal to the current row minus one. This number is then used as the position selector for the row. At this point you have access to the previous row and can get the value of my:field1 from that previous row.

I've tried numerous other combinations using position() and current() with no success. But this one works great. I've tested this pretty extensively and it works each time for me. If someone knows a way to simplify the XPath expression, please let me know!

Finally, please let me know how it works for you.

--
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com



In XPath, how can I say, "go to field1 in the previous repeating section and
return the value in field2 of this repeating section?" I'm trying to do this
with a rule that actions when a new repeating section is made, but the value
in the very first field1 occurs in all field2s in all subsequent repeating
sections. I feel like my indexing isn't right...field2's function seems like
it would be as easy as something like
/my:form/my:repeatingSection/field1[position()-1], but I haven't been able to
get it.

I've tried giving this a go in js (from a previous suggestion), but am only
teaching myself js now, so am having difficulty with this as well...am a bit
new to xpath too.

Any suggestions greatly appreciated...


That does the trick. Thank you very much, I wouldn't have come up with
that...
 

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