Text box with Xpath formula won't recalculate - InfoPath Dev
in

InfoPath Dev

Text box with Xpath formula won't recalculate

Last post 06-20-2009 12:09 PM by pdjohnson_2000. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 06-20-2009 10:01 AM

    Text box with Xpath formula won't recalculate

    Hi everyone,

    I am using the form template feature in InfoPath 2007 and inserting several instances of the same template part into a form. When I do this, it automatically appends and _1, _2 etc. after the field names so they are unique in the form. For example, I have a True/False element in the template part called "complete", and when I insert it several times into a template I get complete_1, complete_2, complete_3, etc.

    What I would like to do is create a field in my template that counts the number of "complete" elements that are checked in the form. Their element names are all different, but they all start with "complete_", so I created the following XPath expression to do this:

    count(following::*[starts-with(name(), "my:complete") and . = 1]) 

    This correctly counts any element who's name starts with the string "complete" and is equal to 1.

    When I give a field this formula as its default value, the value gets set properly when the form opens. The problem is that it does not update as the form changes, even though I have the "Update this value when the result of the formula is recalculated" option checked off. I would expect this to update when I check complete_1, complete_2, etc.

    Can anyone help?

    Thanks in advance!

     

    Filed under:
  • 06-20-2009 10:07 AM In reply to

    Re: Text box with Xpath formula won't recalculate

    Sounds like you're doing it correctly, and I didn't even know that Xpath statement was possible, so that is very cool.  Maybe if you attach the XSN, I might be able to find a slight logic error.  I don't think I could figure it out otherwise, because you're already doing what I would suggest you do to ensure it updates.

  • 06-20-2009 10:23 AM In reply to

    Re: Text box with Xpath formula won't recalculate

    Sorry, here is the file.

  • 06-20-2009 10:40 AM In reply to

    Re: Text box with Xpath formula won't recalculate

    InfoPath seems to have an issue with the following:: axis.  If you change the formula to:

    count(..//*[starts-with(name(), "my:complete") and . = 1])

    then it works, though it seems to me like questionable design to be generating unique node names like that.  Is there a reason why they can't all be named my:complete?  I think that would be more orthodox.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-20-2009 11:37 AM In reply to

    Re: Text box with Xpath formula won't recalculate

    Yeah, I could not figure out how to change that expression properly.  I was having trouble with "following" and with the dot (.) reference.  It seemed to be referencing the numComplete field instead of the complete fields.

    Anyway, Jimmy are you referring to using the Reference function so that all the fields are named the same but contain their own data?

  • 06-20-2009 11:54 AM In reply to

    Re: Text box with Xpath formula won't recalculate

    warrtalon:
    Anyway, Jimmy are you referring to using the Reference function so that all the fields are named the same but contain their own data?

    Either that, or just use a repeating field at the top of the structure, depending on whether he wants all of the item nodes under a common parent or not.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-20-2009 12:09 PM In reply to

    Re: Text box with Xpath formula won't recalculate

    That worked great! Thank you so much!

    The reason I'm using the template parts is that I am building a series of questionnaires and I have about 100 questions that I need to create in various forms. The answer to each question could have a different format (number, text, date, pick list, etc) so I don't think creating a repeating section to hold all of the questions would work. I'm also going to need to create different rules for each question to validate each response, so I think each question needs to be its own node in the data structure. I could use the Reference feature, but then I think I would need to create each question data structure by hand, and with so many to create I would rather not go that route. If I use the template part to represent a single question, I can quickly create the data structure I need (just insert 100 template parts into a form template). Then I can customize from there.

     Thanks again for your help!!

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