In my previous post, I showed you the concept of creating a web service data connection to receive info about the currently logged in user. I showed how you can use information about the current user’s memberships, in order to mimic the user roles functionality. In this post, I’ll show how you can use a similar role functionality, but without having to use any groups at all. No distribution lists from AD, and no SharePoint groups. You’re just going to look at properties of the current user, and perform actions in the form accordingly. I’m going to use the same example that I used in the previous post, of a form that is filled out by end users, but that IT dept users will open to fill out more fields just for them.
Hopefully, your Active Directory profile information is accurate. If it is then this solution will be perfect for you. This method does not use SharePoint groups, but properties of the current user’s profile. This information comes from User Profiles and Properties in Central Administration, which in many companies is imported from Active Directory. We will create a form open rule that looks at the Department field in the current user’s profile.
You’re going to use the “Department” of the current logged in user, in order to determine if the current user is in the IT department. If they ARE, then they will get to see the “IT Dept” view of the form when they open it.
A data connection to the UserProfileService web service will be created again, but this time with a different operation selected.
- Create a new data connection in the InfoPath form, to receive data. The source is a web service. (In SharePoint 2010, pick SOAP web service.) Click NEXT.
- Type the URL of the userprofileservice.asmx file. This is at the root of your SharePoint site, under the _vti_bin folder. Click Next.
- For the operation, click GetUserProfileByName, and click NEXT.
- On the Parameter screen, just leave the default and click NEXT.
- Leave “store a copy of the data…” unchecked, and click NEXT.
- Leave “Automatically retrieve data when form is opened CHECKED, and click FINISH.
- Next, a field will need to exist, in order to temporarily store the department name of whomever the currently logged in user is. This is not to be confused with the name of the department that you may have captured when the person originally filled out the form. This new field’s value will actually change each time a different person opens the form.
- Create a new text field in the InfoPath form. Name it CurrentUserDepartment.
- In the properties of this new field, click the little function button for the default value. fx
- You’re going to set up this field so that it defaults to the current user’s department name. On the Insert Formula screen, click Insert Field or Group…
- Pick GetUserProfileByName as the data source, click the name of the Value field, but don’t click OK yet. Click the Filter Data button.
- Click the Add button, so we can add one filter.
- Pick Name is equal to Department, and click OK on the four different screens.
- This is what your CurrentUserDepartment field’s default value will look like now. Be sure to LEAVE the check box checked, for “Refresh value when formula is recalculated”. Yes, you do want it to be recalculated each time someone new opens the form. Click OK.
Note that you don’t have to actually display this field on the form at all. It can just exist in your list of data source fields. But for testing purposes during form creation, you’ll want to see this.
- Now, when someone opens my form, I want the form to automatically switch to the IT view if the user’s department contains “IT”.
- In InfoPath 2010, click the Data tab in the ribbon, and click the Form Load button, which will bring up the Rules pane on the right.
- In InfoPath 2007, click the Tools menu and choose Form Options. Click the Rules button on the Open and Save section.
- Define the rule:
The condition is: Click the first drop-down box (the field name). Select the name of the CurrentUserDepartment field. Select Contains from the second drop-down. In the third drop-down, choose Type Text… and type IT.
Unfortunately, this screen is case sensitive. So, if a user’s department name is not of the same case, this rule won’t apply.
- Click to add the Action. The action will be just to switch views, switch to the IT Dept view.
- Now try it out. Publish the form. If the text “IT” exists in the department name of your user profile, the form will now automatically switch to the IT Dept view when it opens.
BONUS extra stuff:
- The field that we created in this example is used to simply capture the current user’s department name. If you’d like to create the fields that capture the form originator’s pertinent information like department, phone, job title, etc, you can create text boxes that default to each of those values. But when you do this, be sure to UNcheck the “Refresh value when formula is recalculated” check box. This is because you want the information to initially be captured when the first person fills out the form, but you don’t want it to change after that.
- Also, the CurrentUserDepartment is going to be re-populated each time a different person opens the form, but you may want to do something extra incase the current user’s department field is blank. You can build in an action as part of the submit button, to set CurrentUserDepartment field to blank, that way you ensure that no one will incorrectly see information that does not pertain to them.
Here are a few references that pertain to some of the topics addressed in these last 2 posts of mine:
Auto-Pop Life with InfoPath (Part 1 of 2) – Lori Gowin