Rule to count the number of field that correspond to a specific value - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Rule to count the number of field that correspond to a specific value

Last post 12-22-2016 12:54 PM by Josee Sevigny. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 12-22-2016 08:30 AM

    Rule to count the number of field that correspond to a specific value

    Hi,

    I have the below structure and want to count the number of reviewRequired fields that have a value of 1.

    count(my:reviewers[//my:reviewRequired = "1"])

    In total, there are nodes with a value of 1 but it keeps telling me that there's only 1.  

    <my:reviewers>
      <my:engagementManager>
       <my:ppicker>
        <pc:Person>
         <pc:DisplayName></pc:DisplayName>
         <pc:AccountId></pc:AccountId>
         <pc:AccountType></pc:AccountType>
        </pc:Person>
       </my:ppicker>
       <my:review>
        <my:reviewDate xsi:nil="true"></my:reviewDate>
        <my:reviewRole>Engagement Manager</my:reviewRole>
        <my:reviewRequired>1</my:reviewRequired>
       </my:review>
      </my:engagementManager>
      <my:engagementLeader>
       <my:ppicker>
        <pc:Person>
         <pc:DisplayName></pc:DisplayName>
         <pc:AccountId></pc:AccountId>
         <pc:AccountType></pc:AccountType>
        </pc:Person>
       </my:ppicker>
       <my:review>
        <my:reviewDate xsi:nil="true"></my:reviewDate>
        <my:reviewRole>Engagement Leader</my:reviewRole>
        <my:reviewRequired>1</my:reviewRequired>
       </my:review>
      </my:engagementLeader>
      <my:functionalRRL>
       <my:ppicker>
        <pc:Person>
         <pc:DisplayName></pc:DisplayName>
         <pc:AccountId></pc:AccountId>
         <pc:AccountType></pc:AccountType>
        </pc:Person>
       </my:ppicker>
       <my:review>
        <my:reviewDate xsi:nil="true"></my:reviewDate>
        <my:reviewRole>Function RRL</my:reviewRole>
        <my:reviewRequired>0</my:reviewRequired>
       </my:review>
      </my:functionalRRL> 
    ...
    </my:reviewers> 

    Josée Sévigny
  • 12-22-2016 08:43 AM In reply to

    Re: Rule to count the number of field that correspond to a specific value

    count(my:reviewers[my:reviewRequired = "1"])
    Hilary Stoupa

  • 12-22-2016 08:49 AM In reply to

    Re: Rule to count the number of field that correspond to a specific value

    And if review required is always a number: count(my:reviewers[my:reviewRequired = 1])
    Hilary Stoupa

  • 12-22-2016 10:43 AM In reply to

    Re: Rule to count the number of field that correspond to a specific value

     When I do either, it won't save the rule as it tells me:
    "my:reviewers/my:reviewRequired" does not point to a valid location path of a field or group.


    XPath is: count(my:reviewers[my:reviewRequired = "1"])

    I don't know if this is important but reviewRequired is set as Boolean. 

    Josée Sévigny
  • 12-22-2016 10:55 AM In reply to

    Re: Rule to count the number of field that correspond to a specific value

    Where is the rule? Select reviewers using the field picker and then manually add the XPath filter. Whether "my:reviewers" is a valid path depends on where the rule / condition / expression is. :)
    Hilary Stoupa

  • 12-22-2016 11:07 AM In reply to

    Re: Rule to count the number of field that correspond to a specific value

    Hmm, I'm currently using a Calculated Value control to ensure I can get the correct syntax first, then will move it to when I need it.

    The intent is to hide/show another field (capture date field external to the above structure) based on some calculation within the reviewers mode-set.

    I tried adding an Action rule to the reviewers node to show the count but it does not get triggered. The Reviewers node itself does not get modified nor displayed. So how do I add a formatting rule on my capturing date picker that will actually calculate values from the reviewers structure?

     

     

    Josée Sévigny
  • 12-22-2016 11:42 AM In reply to

    Re: Rule to count the number of field that correspond to a specific value

    A simpler example of what I'm trying to accomplish is to Hide the Submit button, if not all the reviewers have been defined.

    In English, I'd say: For all the Required reviewers, do we have any blank AccoundIDs under reviewers?
    OR
    Do we have the same number of non-blank reviewers as there are required reviewers?

    Seems simple enough but I can't seem to find the number of required reviewers I have.

    Any suggestion? 

    Josée Sévigny
  • 12-22-2016 12:08 PM In reply to

    Re: Rule to count the number of field that correspond to a specific value

    On the submit button, add a condition for your expression - for the first dropdown, select reviewers and use the drop down to select "number of" - that will give you the XPath for the basic count, if you change the first dropdown to "the expression" - paste that into a reply & I can help you w/ the filters on the expression. :) Or attach your form under a reply under the Options tab.
    Hilary Stoupa

  • 12-22-2016 12:30 PM In reply to

    Re: Rule to count the number of field that correspond to a specific value

    Thanks so much for helping.

    First, I had to set the reviewers group as Repetitive even though none of them are. It then allowed me to select "Number of".  HOWEVER, I just noticed that all my People Pickers are now unbound and cannot be bound properly, Yikes!

    count(../../my:reviewers) = "" 

     I tried the following:

    BAD count(../../my:reviewers[reviewRequired = 1])
    BAD count(../../my:reviewers[my:reviewRequired = 1])
    OK BUT RETURNS 1, I SHOULD GET 3 count(../../my:reviewers[//my:reviewRequired = 1])


    Josée Sévigny
  • 12-22-2016 12:35 PM In reply to

    Re: Rule to count the number of field that correspond to a specific value

    OOOOOOHHHHHH ! I understand now that I've looked at your form. I'll post back shortly w/ the formula so you don't have to have reviewers be repeating - I misread your original XML. :)
    Hilary Stoupa

  • 12-22-2016 12:45 PM In reply to

    Re: Rule to count the number of field that correspond to a specific value

     From where your submit button is now, this should be the formula that you can use to disable submit unless all required reviewers have a person selected:

    count(../../my:reviewers/my:*/my:review[my:reviewRequired = 1 and (../my:ppicker/pc:Person/pc:AccountId = "" or not(../my:ppicker/pc:Person/pc:AccountId))]) > 0


    Reviewers does not have to be repeating - I just didn't look closely enough at your sample XML.

    Hilary Stoupa

  • 12-22-2016 12:51 PM In reply to

    Re: Rule to count the number of field that correspond to a specific value

    Found it!!  count(//my:reviewRequired[. = 1])

     Thanks so much! I've lost so much time trying to figure this one out. 

    Josée Sévigny
  • 12-22-2016 12:54 PM In reply to

    Re: Rule to count the number of field that correspond to a specific value

     Great! I couldn't figure out how to jump over the named node ;-)

    Josée Sévigny
Page 1 of 1 (13 items)
Copyright © 2003-2018 Qdabra Software. All rights reserved.
View our Terms of Use.