Counting Number of Occurrences of Attachment Controls Where File Attached - InfoPath Dev
in

InfoPath Dev

Having trouble finding a blog or post that answers your question? Check out our Custom Search Page

Counting Number of Occurrences of Attachment Controls Where File Attached

Last post 10-27-2008 09:06 PM by cbrown00. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 10-26-2008 09:08 PM

    Counting Number of Occurrences of Attachment Controls Where File Attached

    I'm using 5 attachment controls scattered across a form.  Each has a repeating group so multiple files could be attached at each attachment control.  When a user completes the form, I would like a control to count how many of the files have been attached and use that ensure none of the files are missed.

     How can I count the number of instances where a file has been attached?  It should count the total number of files attached.

     thanks

  • 10-26-2008 10:10 PM In reply to

    Re: Counting Number of Occurrences of Attachment Controls Where File Attached

    Supposing you had a file attachment control bound to /my:myFields/my:group1/my:group2/my:fileField, where my:group2 is a repeating group, you can find the total number of file attachments in the group with

    count(/my:myFields/my:group1/my:group2/my:fileField)

    Note that this is only for explication and you don't have to type this all by hand.  In the InfoPath expression builder, you would just click "Insert Function...", select count, double-click the underlined part and select the attachment's field.

    This would also count the number of file attachments where a file isn't attached, so to count only the attachments that have a file attached, you can use:

    count(/my:myFields/my:group1/my:group2/my:fileField[. != '']) <-- note these are two single quotation marks '', not one double quotation mark "

    You could also apply the "cannot be blank" property to the fields to ensure that they all have a file attached. Now if you want to add up the counts of file attachment fields in several repeating groups, you can sum them all up in an eval function,

    xdMath:Eval(., "count(my:group1/my:group2/my:fileField1[. != ''])+count(my:group3/my:group4/my:fileField2[. != ''])+count(my:group5/my:group6/my:fileField3[. != ''])")

    Note that in this case, the node paths do not begin with a forward slash, because they are all relative to the starting node (just a dot here, indicating the root node.).

    You won't need to worry too much about the details if you use the buttons and dialogs to insert the functions and nodes.

     

    Jimmy Rishe / Software Developer / InfoPath MVP
    Qdabra Software
    Filed under:
  • 10-27-2008 09:06 PM In reply to

    Re: Counting Number of Occurrences of Attachment Controls Where File Attached

    Jimmy...worked liked a champ!...thanks

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