Count results of filtered section/table - InfoPath Dev
in

InfoPath Dev

Count results of filtered section/table

Last post 05-07-2013 03:58 PM by Doreen. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 03-17-2009 12:31 PM

    Count results of filtered section/table

    I have a repeating section bound to a repeating field in my data source.  When I use the Filter Data functionality to filter, how can I retrieve the number of items that will still be shown?

    Thanks for any help.

  • 03-18-2009 02:16 AM In reply to

    Re: Count results of filtered section/table

    Hi,

    Use the count("repeating section xpath ") function. By using this you can get the number of rows are inserted in repeating section.

    Swathip
    www.ggktech.com
  • 03-18-2009 07:01 AM In reply to

    Re: Count results of filtered section/table

    Hi swathip,

    Thanks for your reply.  I know the count() function, but it does not give me the result I am looking for.

     Say my repeating data source has 12 rows in it.  For the repeating section filter in Infopath, I use an xdExtension to call a function that returns true or false, so the filter can include or discard that row.  When I have this, 4 rows are shown that make it through the filter.

    If I make an expression box with count(xpath) as you suggested, its value is still 12.  However, if I put an expression box with position() in the repeating section, the values shown a 1, 2, 3, and 4.  So, the position() function can account for filtered data; I need something similar for count().  Any ideas?

  • 03-18-2009 10:16 PM In reply to

    Re: Count results of filtered section/table

    Hi,

    Add a Boolean field to the repeating section in data source with the default value as false. You are using a function which returns true or false. Set that value to the newly added boolean field.  Use this field to filter the rows. For example, count("my:myFields/my:group1/my:group2[my:booleanField = ‘true']")

    Swathip
    www.ggktech.com
  • 03-19-2009 07:17 AM In reply to

    Re: Count results of filtered section/table

    Thta is exactly the solution I ended up going with a couple days ago.  Seems silly that position() can account for this but count() can't.  Oh well.

    Thanks again swatip!

  • 03-19-2009 09:05 AM In reply to

    Re: Count results of filtered section/table

    I think that once you understand XPath a bit better, you'll find that there's really nothing silly about this behavior.  When you filter a repeating section, you are only concealing certain rows from the visual representation of the data, not removing nodes from the data itself. The XPath functions are concerned with the contents of your data source, not the current appearance of your InfoPath view.

    Consider this: if you had two repeating sections bound to the same repeating group and filtered on different values, what value would you expect count(full path to node) to return?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 03-19-2009 09:25 AM In reply to

    Re: Count results of filtered section/table

    I understand XPath, count, and that nothing in my data source is actually being modified, and I think the way count() works makes perfect sense and should function no other way (otherwise, how would you truly know the number of items in the data source?).  I was just hoping to have the functionality to count the filtered nodes without having to introduce an otherwise unnecessary field into to my schema.  And since position() is able to detect this, I thought there may be  way with proceeding-sibling or following-sibling or something along those lines to do this.

  • 03-19-2009 10:06 AM In reply to

    Re: Count results of filtered section/table

    Pardon me for assuming you knew less than you did.

    I think there are ways to get around using that extra boolean field.  For example, there is a way to hack the form to allow calling xdExtension functions from rules and (I believe) expression boxes:

    http://www.infopathdev.com/blogs/greg/archive/2004/09/15/Use-Code-to-Determine-a-Rule-Condition.aspx

    Another option, since you're already using code anyway, is to set a named node property on the relevant fields, and then use xdXDocument:GetNamedNodeProperty(,,) in your count() expression.  This should enable you perform these counts without adding unwanted fields to your form.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 03-19-2009 01:26 PM In reply to

    Re: Count results of filtered section/table

    Hi Jimmy,

    I suppose I should have been more clear about my expectations of count().

    I've seen this post by Greg before, and use xdExtensions multiple places.  They work in rules and filters, but if I try in an expression box I receive the error "Reference to undeclared namespace prefix: 'xdExtension'."

    I was able to use NamedNodeProperty, as you suggested, to perform my calculations.  It behaves similarly to an attribute, from what I can tell.

    I set the value in code:  XDocument.SetNamedNodeProperty(node, "show", "false" or "true")

    Use it to filter:  xdXDocument:GetNamedNodeProperty(., "show", "true") = "true"

    And also to put the count in an expression box: count(../../my:Deficiencies/my:Deficiency[xdXDocument:GetNamedNodeProperty(., "show", "true") = "true"])

    Once again, thank you very much for your help!

  • 10-29-2010 11:04 AM In reply to

    • Desmo
    • Not Ranked
    • Joined on 09-17-2009
    • Posts 14

    Re: Count results of filtered section/table

     hi sorry to be bumping an old message but I am having difficulty w/ this one - when you say to add a boolean field in the rep. section,  what type of function should it be? there's nothing that seems to evaluate whether or not the field itself is b eing displayed.    if it's default is "false", what is supposed to make it true so i can count the "trues"? if that makes sense

  • 05-07-2013 03:58 PM In reply to

    • Doreen
    • Top 50 Contributor
      Female
    • Joined on 08-11-2010
    • Federal Way, WA
    • Posts 291

    Re: Count results of filtered section/table

    Desmo,

    did you figure this out?  I have same question but this thread is so old nobody will likely respond.

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