LAST() - InfoPath Dev
in

InfoPath Dev

LAST()

Last post 01-19-2010 05:31 AM by Qazi Anis. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 01-19-2010 03:10 AM

    LAST()

    Hi, this is a very very noob question, but I cannot seem to find anything at all on just the basics of using the last() function through Default Value and Rules.

    I have a repeating table, and my first field is ProjectName. When I insert a new line, I would like to default ProjectName in the new line to the same value in the above line. I am not using any coding on my form, so just though f(x). I am able to put OtherField[last()] which is accepted, but if I am using the current field, it defaults to '.' and .[last()] is not accepted.

    This is very frustrating, please help.

    J

  • 01-19-2010 04:07 AM In reply to

    In essence, last() evaluates to the number of nodes that match a certain XPath pattern, up to the point where last() appears, so if I had this XML:

    <animals>
        <cat>
            <name>Felix</name>
        </cat>
        <dog>
            <name>Fido</name>
        </dog>
        <cat>
            <name>Paws</name>
        </cat>
        <dog>
            <name>Fido</name>
        </dog>
    </animals>

    In the expression

    /animals/cat[last()]/name

    last() would evaluate to 2 (because there are two nodes that match the pattern /animals/cat), and the XPath above would select the <name> node with the value Paws.

    For this reason, .[last()] doesn't make a lot of sense, because . is always the current node, and only the current node.

    If you want to select the last sibling of a certain node, try going one step up the tree and back down again:

    ../my:nodeName[last()]

    or using the following-sibling axis:

    following-sibling::my:nodeName[last()]

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-19-2010 05:05 AM In reply to

    Thanks for the reply Jimmy, that made sense.

    Following that then, I used the expression: RisksTbl[last()]/ProjectName which was accepted no problem. However, if I set the field default value to this, and insert a new line, the value is not defaulted to the last value... Would this be because the new node is already created, so Last would be looking at empty values? I tried to use last() - 1, but that gave a blank.

  • 01-19-2010 05:25 AM In reply to

     Could it be that you don't have the "Update this field when the value changes" box checked?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 01-19-2010 05:31 AM In reply to

    default values are set once a field is created so when you say default value to be riskstbl[last()]. infopath refers to the last row(i.e. the one you just created)

    Qazi Anis
    Technical Architect
    Bitwise Inc
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.