What are Roles? Without going much in detail, InfoPath roles is a functionality where you can define user tags like "Sales", "Management" and utilize them in your form logic. This enables some very interesting scenarios in the forms space. For a detailed discussion on this topic, take a look at this MSDN lab. If you have worked with InfoPath 2003, you would notice that Roles have not changed much in 2007, and that they are not supported by InfoPath Forms Services. My focus will be in how we can enable role-related scenarios in browser forms.
For the purpose of this article, lets borrow the scenario from the lab. - "The management team at Contoso Corporation reviews each of the Sales Report filled out by sales representatives. Because the management team is interested only in sales deals that exceed a certain amount of money, your department is asked to add an additional view to the sales form that shows only those deals"
STEP 1: Find a way to store role-related data
You can store information about which users belong to which grounps in an XML file, included as resource as a part of the XSN. Here's one way to organize this XML file:
<?xml version="1.0" encoding="utf-8"?>
Create a data source pointing to this resource file and use this data source to make decisions in step 2.
Variation: Roles and Users relationship might be stored in a database (say HR system). You would then create a secondary data source connecting to your HR System instead of the XML file mentioned above; everything else stays the same.
STEP 2: Determine the role of the current user
1. Add hidden fields to the main data source of your form. These will store:
2. Set the detault value of CurrentUser to the username() function.
3. Set "CurrentRole" value to
name[username = CurrentUser]
name[username = CurrentUser]
STEP 3: Use rules and CurrentRole
To accomplish our scenario, we will create two views: one for "Sales", and one for "Management". Using Rules, you can switch to the appropriate view on load of the form:
1. With the form template in design mode, on the Tools menu, click Form Options.2. Click the Open and Save tab, and then click Rules, and the following two rules:
And that's it! You can use CurrentRole the same way you'd have used Roles in the InfoPath smart client. Note that this trick works on the smart client, too - so if you want to create a roles-based InfoPath application, this method will help.
Pradeep RasamProgram Manager
PingBack from http://stephenmuller.wordpress.com/2007/03/25/infopath-2007-forms-services-roles/
I know it sounds stupid but is there a special way to add hidden fields or we need to insert a text box and somehow make its visibility false? More, I cannot set the second formula with XPath and UserName() function does not show the user name on the textbox. Can u detail on these a bit? I am brand-new to Infopath :(
Correct me if I am wrong, but I think the correct formula to use for "CurrentRole" would be "users[username = userName()]/../name", at least that is working fine for me. In the xml, the username node is not a child but a sibling to name and thus name[username = CurrentUser] is not actually working. Am I doing something wrong? Also, I have solved the mystery of the UserName() thing....I should keep it as a rule which evaluates it when the form loads.
users[username = userName()]/../name
is working for me. The error I get is: " does not point to a valid location path of a field or group."
ok, according to Sayagh, this is how I got my CurrentRole formula:
xdXDocument:GetDOM("FetchRoles")/roles/role/users[xdXDocument:GetDOM("FetchRoles")/roles/role/users/username = xdUser:get-UserName()]/../name
However, no matter which user I am under, Currentrole always returns the first role on the list (which I called <name>Conception</name>).
Please check my blog for complete solution.
Here's my method of doing this: http://claytoncobb.wordpress.com/2009/06/14/user-roles-in-browser-enabled-forms/.
I've improved my method and am now utilizing Active Directory security groups and distribution lists for defining my roles in browser forms: