Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

InfoPath and the Count Function

  Asked By: Virginia    Date: Apr 27    Category: Sharepoint    Views: 10565

I have an InfoPath form with a field called "Dept" that displays the deparment
of the creator of the form. Once the form is created and saved, the Dept field
is displayed as a metadata field in the document library. Every time a user
creates a new form, I have a box that displays a count of how many form has been
created within their department. I created a data connection to the document
library and I'm pulling from the Dept field. For that box on the form, I have
the following formula: count(@dept)=Dept. The "@dept" is the metadata field in
the document library and "Dept" is the value in the Dept field on the InfoPath
form. When I run this form, the box keeps displaying "false". I'm looking for
any recommendations and even if this is possible.



3 Answers Found

Answer #1    Answered By: Alka Sarabhai     Answered On: Apr 27

It looks like you're performing an equality test between count(@dept) and
the Dept field  (which would evaluate to false  since you haven't set the
field's value yet). I'd think you would simply want to display the result
of the count  function in your field (so you can lose everything right of the
closing parenthesis).

If on the other hand you're assigning the field from an event handler
somewhere else on the form, you'd want to flip the equality assignment so
you're not assigning the value of the field to the result of the function
(which isn't possible anyway).

Answer #2    Answered By: Eashan Nadkarni     Answered On: Apr 27

If I understand you corretly, my
formula count(@dev)=Dept displays  false because since I have not saved  the form,
it cannot grab the value for the Dept field  on the form  right? I do not have any
coding experience, but is it possible to grab the Dept field ahead of time? If
the users' profile can pull the department  from AD and store it in sharepoint,
would I not be able to get this value ahead of time  using the sharepoint web

Answer #3    Answered By: William Odom     Answered On: Apr 27

I figured it out (my method is only possible in IP 2007),
and here's how:
First, you need to make sure the "Department" user profile property
is available in the user information list on the list. Go into the
SSP, to user profile properties, to the department  property. Put a
check box  next to "Show in the profile properties section of the
user's profile page".

Create the following 2 data  connections in the InfoPath form,
connected to the site that the form's doc library  is on.
User Information list - At least select the "User_Name"
and "Department" fields, and I put check boxes to "store a copy of
the data in the form  template", and "Automatically retrieve data when
form is opened".

Connect to your form's doc library - at least select the User
Department field, and I put check boxes to "store a copy of the data
in the form template", and "Automatically retrieve data when form is

created  2 fields:

UserDept - the formula  is @Department[@User_name = userName()]
This is how: Create a (read only) text box, and for the default
value, click "Insert field  or group", and change the data source drop
down to the user information list. Select the Department field, and
click the "Filter Data" button. User_name is equal to (Use a
formula) and choose UserName. This username formula is only
available in InfoPath 2007.

Cool, now this field automatically displays  the department name of
the currently logged in user!

CountDept - the formula is count(@Department[. = UserDept])
This is how: Create a (read only) text box, and for the default
value, click "Insert field or group". For the data source, select
the name of your data connection  to the form's library. Select the
Department field, and the "Filter Data" button. Department is equal
to UserDept.

Now, this field will show the total number of records for that user's

When you publish the form, be sure to send these 2 new fields to the
doc library as columns.

Didn't find what you were looking for? Find more on InfoPath and the Count Function Or get search suggestion and latest updates.