Turning Repeating Table values into a sentence. - InfoPath Dev
in

InfoPath Dev

Turning Repeating Table values into a sentence.

Last post 07-13-2012 09:59 AM by Anson Hidajat. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 07-12-2012 07:13 AM

    Turning Repeating Table values into a sentence.

    I'm trying to turn a list of attendees in a repeating table into a thank you sentence.

    For examples, the values in the repeating table look like:

    Jim
    Tim
    Lisa
    Fred

    I need the sentence to say:

    "Special Thanks to Jim, Tim, Lisa, and Fred."

    Consider the following repeating table structure:

    groupAttendees
        groupAttendee
           fieldAttendeeName

    I could create the sentence "Special thanks to Jim, Tim, Lisa, Fred, " all day using nested evals:

    concat("Special thanks to ", eval(eval(groupAttendee, 'concat(my:fieldAttendeeName, ", ")'), ".."))

    However this does not give me the desired result with the "and" before the last table entry.  I searched around and could not find a way to enter the "and" in the sentence just before the last table entry.

    So here's my thought process:

    1) Assign a Line Item number to each table entry.
    2) Count the number of rows in the table.
    3) If the line number is less than the row count, concat a string
    4) If the line number is equal to the row count, concat the and string
    5) concat the two strings together

    Implementation:

    1) Assign a Line Item number to each table entry.

    Modified repeating table structure by adding fieldAttendeeLineItem:

    groupAttendees
        groupAttendee
           fieldAttendeeName
           fieldAttendeeLineItem

    assigned fieldAttendeeLineItem default value of:

    count(../preceding-sibling::*) + 1

    2) Count the number of rows in the table.

    created a field outside the repeating table named fieldRowCount with a Default value of:

    count(groupAttendee)

    3) If the line number is less than the row count, concat a string

    eval(eval(groupAttendee[msxsl:string-compare(fieldAttendeeLineItem, fieldRowCount) < 0], 'concat(my:fieldAttendeeName, ", ")'), "..")

    The results of such a string would be:

    Jim, Tim, Lisa,

    4) If the line number is equal to the row count, concat the "and" string

    eval(eval(groupAttendee, 'concat("and ", my:fieldAttendeeName[../my:fieldAttendeeLineItem = ../../../my:fieldRowCount], ".  ")'), "..")

    The results of such a string would be:

    and Fred. 

    5) concat the two strings together

    created a field outside the repeating table called fieldAttendeeThankYou with the Default Value:

    concat("Special thanks to ", eval(eval(groupAttendee[msxsl:string-compare(fieldAttendeeLineItem, fieldRowCount) < 0], 'concat(my:fieldAttendeeName[../my:fieldAttendeeLineItem < ../../../my:fieldRowCount], ", ")'), ".."), "and ", fieldAttendeeName[fieldAttendeeLineItem = fieldRowCount], ".  ")

    Got what I wanted:

    Special thanks to Jim, Tim, Lisa, and Fred.

    I'll have to add some logic for blank fields, if there is only one name, etc, but you get the idea.

    If anyone has a simpler way, please let me know!

    ~Dustin.

    Filed under: ,
  • 07-13-2012 09:59 AM In reply to

    Re: Turning Repeating Table values into a sentence.

    This is awesome!  Will definitely use this in the future.  Thanks for sharing :)
    Anson Hidajat
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.