Getting all current user’s SharePoint permissions groups in InfoPath 2010
I followed this great post by Jaliya Udagedara on how to get a current user SharePoint group name in InfoPath, but I needed something a bit different, first of all I was working with an InfoPath form library and not a customized SharePoint list form, secondly I had a scenario where I wanted to show or hide different sections of my InfoPath form to different users according to their permission group, while it’s possible that they belong to several groups.
The basic idea was that I published my InfoPath form as a content type and added this content type to several libraries, than I’d modified my form to include submit data connections to each library.
Afterwards I’d added several buttons each of them submitting the form to a different library, each button is visible only to users belonging to the corresponding library’s permissions group, or to administrative users that are able to choose the library they wish to submit the form to.
So in order to get all of the current’s user permission groups in an InfoPath text field, follow Jaliya’s post up until step 5 (not including).
Then go to Data -> Form Load and create these 2 actions:
1. Set a field’s value: set the ‘userLoginName’ field on the GetGroupCollectionFromUser data connection (make sure you update this field under the connection’s queryFields group and not under the dataFields group where there is a field with the same name), set its value with the value returned by the GetUserProfileByName connection where – Filter (Name = “AccountName”).
2. Query for data the GetGroupCollectionFromUser data connection.
Create a new text field (I’ve named it CurrentUserPermissionGroups but you can name it anything you’d like), set its default value to contain this formula –
eval(eval(Group, ‘concat(@Name, “;”)’), “..”)
You can copy and paste this formula in to your text field’s default value formula, and then just re-select your group from your GetGroupCollectionFromUser data connection like so –
That’s all! Now your field should show all of the current user permission groups (under the site collection of your data connections) -
To hide or show fields simply add formatting rules checking if this field contains the group in question -