1

How can I restrict view to a user or a group of users? I'm able to get their name or membership but how do I then apply it to the actual webform? InfoPath has lot less options for SP lists and webforms and I can't seem to find a solution.

In short:

I have two views, both available to all

What I want:

First view be available to all Second only to privileged users

0

You can achieve this with a Form Load Rule under the ribbon Data -> Rules. Then you can switch views based on e.g. a field value. In this field you should store data about membership.

  • can you expand on it? I know that I need to get some information but my question is - what do I actually do with it? How do I use it to restrict the access? – JurajB Sep 16 '15 at 2:57
0

You can create a hidden field in which you can store the names of the person whom you want to restrict the certain views. On the form load event check whether the current logged in user lies in the group of authorized users, if yes then show him the view which he is authorized to see and if he isn't authorized then switch the view to the one which he is able to access. Make this check on the form load event or form load rule.

  • can you be more specific as to how to do it? I am able to get the username of the current user, but not a group - how do I do that? even if successful, how do I actually restrict the view? – JurajB Sep 16 '15 at 2:55
  • You can have another text box where you store the name of the SharePoint groups that are allowed to access the view. On form load you can get the group of the current user by creating a data connection to the user profile service. Once you get this group of the current user, compare it with the groups in the textbox and if they come out to be same then switch to the view which he is allowed to see and if the condition is false switch to another view that he can access. You will be required to write down two rules on the form load event. to switching the views. – Mancy Desaee Sep 16 '15 at 4:32
  • Actually I need one group to access one view, the other both views. I added a button for changing views and wanted to only have displayed to the second group but how do I actually do it? – JurajB Sep 16 '15 at 22:21
0

Check this blog. I followed the steps in 2010 and it worked. To summarized, you will need two web services. One is GetUserProfile and UserGroup. UserGroup will be used to get the current logged user's group. You will use this to set rules in your form to hide the views.

This is a long process but it works.

http://info.akgroup.com/blog-0/bid/69277/InfoPath-Restrict-visibility-to-users-in-a-SharePoint-Group

  • That's great, that worked apart from one important thing, the username returned in a webform is a generic account rather than the proper user account – JurajB Oct 7 '15 at 22:25
  • what do you mean by generic? Is it created like an alias? – Mekalikot Oct 8 '15 at 1:12
  • through webform and CLAIMS authentication I got the SharePoint username rather than the users. I used userName() function instead which does return correct username via webform so all good. Now just work out how to check against the group as that didn't seem to work (I will replicate the steps again to make sure I didn't make a mistake) – JurajB Oct 9 '15 at 3:34
  • Have you tried adding the users to a sharepoint group that you want to be restricted? Also, try using the UserProfileService.asmx -> GetUserProfileByName webservice, it also gets the current logged user. – Mekalikot Oct 9 '15 at 4:53
  • it doesn't in a webform, that's why I had to use userName() – JurajB Oct 12 '15 at 2:05
0

Mekalikot's link got me on the right track however there were couple of issues - CLAIMS authentication and webform

http://info.akgroup.com/blog-0/bid/69277/InfoPath-Restrict-visibility-to-users-in-a-SharePoint-Group

To resolve that, I found a comment below that demonstrated how to do it a bit differently without going into that much effort after all.

You don't need to get the username through UserProfileService.asmx service, but use userName() function which you can call directly and check against the group. You will need to get the group and adjust the code as it says in the article though

Jon in the comments suggests to create 3 actions which does work and I finally made it work so here it is:

action #1

  1. Click Data Tab in Infopath 2010.

  2. Click Form Load in the Rules section.

  3. Click New, Add an Action rule, leave the Condition as None since this needs to run everytime

  4. Go down to "Run These Actions:", Click Add dropdown then select Set a Field's Value

  5. In Field: Click the button to the right of the Textbox

  6. Choose your Connection "GetUserCollectionFromGroup" at the top under Fields:

  7. Go down myFields -> queryFields -> ns1:GetUserCollectionFromGroup -> select groupName, click ok

  8. In the value put the name of the Group you want to search for.

action #2

  1. Click the Add dropdown and select "Query for Data"

  2. Set the Data connection to query your "GetUserCollectionFromGroup" and hit Ok

action #3

  1. Click Add dropdown then select Set a Field's Value

  2. In Field: Click the button to the right of the Textbox

  3. Choose your Connection "Main" at the top under Fields:

  4. Select the Boolean True/False field you created above in the tutorial and click Ok

  5. Click Fx button to the right of the Value Textbox

  6. Click Insert Field or Group then select the connection at the top to "GetUserCollectionFromGroup"

  7. Click myFields -> datafields ->ns1:GetUserCollectionFromGroupResponse -> GetUserCollectionFromGroupResult ->

GetUserCollectionFromGroup -> Users -> User -> LoginName

  1. Select LoginName then click "Filter Data..." and click Add

  2. On the Filter Conditions have "LoginName" selected "is equal to" and select "Use a Formula" in the right most box

  3. Click "Insert Function" and select the UserName() function. Click Ok, Ok, (Filter Data) Ok, Ok and Stop when you get to Insert Formula

  4. In the Forumla: you should see @LoginName[. = userName()] go ahead and put the Boolean(count() > 0 ) in there.

Should look like this

boolean(count(@LoginName[. = userName()]) > 0)

  1. Once the Formula: looks like above click OK, then OK again.

This did it for me - I got a correct username, checked against the SharePoint group and was able to hide or appear an element based on the user group.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.