Saturday, November 22, 2008

Getting Current user role in Infopath code-behind

Scenario:
Infopath 2003/2007 has .net language support. In your code you want to do execute some logic depending upon the Logged in User Role.

Solution:
You can use the in-build method to get the role.

Code:


bool userRole = thisApplication.User.IsUserMemberOf(@"Domain\Group");

if (userRole)
{
//do something cool here
}
Notes:
However, there is a catch here. This works only if the user who is accessing the form and the group specified in the user roles are of the same domain.

So, the following are the valid and invalid combinations

Invalid Combination:

User: AMERICA\Employees
Group: ASIA\SecurityGroup

Valid Combination:

User: AMERICA\Employees
Group: AMERICA\Administrators

0 comments: