Count of a multiple-selection list box. - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Count of a multiple-selection list box.

Last post 04-11-2014 01:24 AM by holdemryan. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 10-20-2009 12:07 PM

    Count of a multiple-selection list box.

     Good afternoon.

     I'm having a terrible time with something that SEEMS relatively easy. I have 2 fields, Insurance_Products and Number_Of_Policies.  Insurance products is a multiple selection box with 12 entries in it.  All i'm trying to do is set the Number_Of_Policies field to equal the number of selected items inthe Insurance_Products box.  (So if the user selects Home, Auto and Life from the Insurance_products box, Number_Of_Policies should equal 3.)

     

    I for the life of me cannot figure out how to do this.  I've tried using the count function (only returns a value of 1) and tried just incrementing the Number_Of_Policies field. (This doesn't work because I cannot figure out how to subtract from the field is an item in Insurance_Products is de-selected.)

     

    Any help on this would be greatly appreciated.

  • 10-20-2009 06:03 PM In reply to

    Re: Count of a multiple-selection list box.

     The count() function is the way to go.  Could you show us a small description of the area of your data source where the listbox is bound (a screenshot, or a simple mock-up in text), tell us to which field the listbox is bound, and show us the count() formula you're trying to use?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 10-21-2009 05:32 AM In reply to

    Re: Count of a multiple-selection list box.

    Hey Jimmy,

    Thanks for the reply.  I was just using the Count() function wrong.  I tried using it as the default value for my textbox (to update when a field changes.) but it would only update once.

    I simply created a button that gets the count AFTER information is entered into the multiple-selection box.

  • 10-21-2009 06:01 AM In reply to

    Re: Count of a multiple-selection list box.

     Neat.  You might also try doing that from a rule on the list box's field, so that users don't have to press a button to update the number.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 10-21-2009 06:15 AM In reply to

    Re: Count of a multiple-selection list box.

    Hey Jimmy, THis is actually what I'm attemptingto do!  I created a rule in the multi-select list box to set the value of my other field to Count(multi-select field).

    The problem is it will only display a count of 1.  Attached are pictures of what I tried to do.  Name of my listbox field is Type_of_Policy_Referred and my field i'm trying to set is called Number_Of_Policies.

     

     


  • 10-21-2009 06:16 AM In reply to

    Re: Count of a multiple-selection list box.

     


  • 10-21-2009 07:11 AM In reply to

    Re: Count of a multiple-selection list box.

    I just tried this for myself, and found it's a little tricky because of the way multi-select list boxes add and remove nodes on the fly.  The solution I found requires a combination of a rule and a default value.

     First, change the expression in your rule to:

     count(../my:Type_of_Policy_Referred)

    (I'm assuming my: is the right prefix, but it might be something else).

    Then set the default value on Number_Of_Policies the same way you did in your button rule, by inserting the count() function and using the Select node... dialog to insert the node reference inside.

     Those two together should do the trick.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 05-06-2010 10:02 AM In reply to

    Re: Count of a multiple-selection list box.

    Thank you very much for this - I thought I understood it... didn't you just know there was going to be a but.

    I have a repeating field /my:myFields/my:SKUIntroductionGroup/my:Region.  This is a multi-select box on the form.

    I want to ensure that the user selects at least one value.  I cannot use "cannot be blank" property because there is always a blank one... unless I use code to delete it.

    So I thought I would have a temporary variable that I could update with the count of non blank regions - and then base a validation on that count.   Using the help above I have put a rule on my:Region  to  update a temporary variable  with count(../my:Region[. != ""]).

    This works when you are adding regions - but is not fired when you untick a box.  If the last thing you do is untick - then the count is wrong.

    What have I missed ?  Is there a better way to validate that at least one Region is non blank

    Catharine

  • 07-16-2013 03:47 AM In reply to

    • Monali
    • Not Ranked
    • Joined on 05-14-2013
    • Posts 7

    Re: Count of a multiple-selection list box.

    What i understood is ,one rule on multiple selection listbox and default value for text box. Can you please explain how to set that rule ,expression. I tried with,i copied the xpath of multiple selection and pasted in the rule. but not working
  • 04-11-2014 01:24 AM In reply to

    Re: Count of a multiple-selection list box.

    I'm getting some odd behaviour for this. MSLB has a rule when Field Value changes a simple Count(MSLBFieldName) and the default value for the traget field has the same.

    The value starts off at 1 before I've even started selecting items in the MSLB. It then adds and removes correctly, but it is still 1 ahead of the actual number of items selected.

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