Using count() with secondary datasource - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Using count() with secondary datasource

Last post 07-02-2020 11:42 AM by Hilary Stoupa. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 07-02-2020 09:25 AM

    Using count() with secondary datasource

    Hi! I'm trying to use the count() function within a repeating table on a filtered secondary data source and struggling with counting within the current row. To avoid running a query each time a new row is added, as this seems to conflict with the previous row's selections, I've loaded the data on form load (~680 records) and then use some drop-downs to build a filter that selects from the secondary datasource and works reliably from row to row. I am able to count the first row correctly, however when I add a row, the count stops working and it becomes additive based on # of rows. (row A has 2 entries, row B has 1 entry, count becomes 3 on both) I tried using current(), however, I can't seem to get it to work in-place of getDOM() on the secondary data-source. Essentially, I'm trying to do an error check so that the count of rows = number of filtered entries. If anyone has any suggestions on how to make this work or a better way to run this check, I'd greatly appreciate it. Code is as follow: count(xdXDocument:GetDOM("BookStoreInventory")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ISBN[../d:year = xdXDocument:get-DOM()/my:myFields/my:Year and ../d:term = xdXDocument:get-DOM()/my:myFields/my:Term and ../d:EventID = xdXDocument:get-DOM()/my:myFields/my:ClassForm/my:ClassGroup/my:Class/my:TempFilter])
  • 07-02-2020 09:57 AM In reply to

    Re: Using count() with secondary datasource

    So - can you attach a copy of your form, or post a screenshot that shows the main data source structure, in a reply under the options tab? Is "my:Class" the repeating group? Is this count going in a field as a default or in a calculated value in the repeating table?
    Hilary Stoupa

  • 07-02-2020 10:32 AM In reply to

    Re: Using count() with secondary datasource

    Thanks for the lightning fast reply!!! Attaching main data screen shot. I'm using a rule to set the NumberOfBooks field as I thought I might be able to get away with using the current function there. I'm open to using it as a default value; just thought the rule might give some flexibility.
  • 07-02-2020 10:38 AM In reply to

    Re: Using count() with secondary datasource

    What field is the rule on?
    Hilary Stoupa

  • 07-02-2020 10:42 AM In reply to

    Re: Using count() with secondary datasource

    CourseSection
  • 07-02-2020 11:07 AM In reply to

    Re: Using count() with secondary datasource

    Maybe try this? count(xdXDocument:GetDOM("BookStoreInventory")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:ISBN[../d:year = xdXDocument:get-DOM()/my:myFields/my:Year and ../d:term = xdXDocument:get-DOM()/my:myFields/my:Term and ../d:EventID = current()/../my:TempFilter])
    Hilary Stoupa

  • 07-02-2020 11:13 AM In reply to

    Re: Using count() with secondary datasource

    So... 1) That worked; thank you SOOOO Much! 2) I guess the trick is, with current(), is that it replaces the entire path?
  • 07-02-2020 11:23 AM In reply to

    Re: Using count() with secondary datasource

    For me, it is easiest to think of "current()" as meaning "this element" (whether a group, a field, an attribute). So, in the case of your specific function - the TempFilter was the item in the repeating group that we needed to use current for. The rule is on CourseSection, so in this case, current() = "this specific instance of CourseSection" - because there could be a lot of them! Their grandparent is repeating! So, to get to TempFilter in the same Class (which will be in the same ClassGroup) we use current() to indicate this specific course section, go up the tree to the parent of the course section, and get the value of the temp filter that is in the same parent.... does that make sense? Since your other two filter fields are not repeating, it is ok to use the absolute instead of a relative path. :)
    Hilary Stoupa

  • 07-02-2020 11:36 AM In reply to

    Re: Using count() with secondary datasource

    That is, by far, the best explanation of how those paths work, I've read. I don't really know why I wasn't wrapping my head around it. Thank you, again, for the solution as well as the lesson!
  • 07-02-2020 11:42 AM In reply to

    Re: Using count() with secondary datasource

    It took me the longest time to understand this stuff. I still find myself saying "up the tree" as I type ../ when writing XPath. :)
    Hilary Stoupa

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