Friday, June 3, 2011

Switching Infopath Views based on User Departments

During Sharepoint intranet portal development, i have experienced a problem that i need to display infopath forms differently to different departments (as a common Intranet portal have departments in it).I have noticed that the production environment haven't setup correctly i.e. User profiles were not synchronized by the sharepoint administrator and hence, the sharepoint user profiles doesn't have complete information of the users. 

I have overcome this problem by doing the following steps:
1- create security group for that particular dept
2- follow the steps of this link
http://blog.ianchivers.com/2011/01/using-sharepoint-usergroup-web-service.html 
and make a data connection "D1"
3- Now add a choice field in infopath form.
4- set its default value like this
boolean(@ID[@LoginName = concat(substring-before(@LoginName, "\"), "\", userName())])
where,
ID = D1 -> Data fields -> .... -> ID
LoginName -> D1 -> Data fields -> .... -> LoginName
boolean(), concat(), substring-before() and username() are the builtin infopath functions

Now On FormLoad Event, if choice field value equals your desired value, then switch the view...

No comments:

Post a Comment