For those of you who have been using InfoPath long enough, you have likely had a request to pull information about a user. The user may be the current user or it may be a user within a field. In either case, doing some quick internet searches will point you to using web services of ‘getuserprofilebyname’ or ‘usergroup’.
That’s all well and good… except if you attempt to use either of these web services, you are greeted with an error “An error has occurred while trying to connect to a Web Service.” Per Microsoft, this is a result of a security measure called ‘loop back protection’. See here:
Longer answer, thanks to combining both of these sources:
Steps to implement:
- Build your InfoPath form any way you want. This can be a list with a customized InfoPath form or using a Form Library.
- Add a text field to your list or library to store the SharePoint group. We chose the field name ‘SPGroup’.
- Add the field to the actual input InfoPath input form whether you want to or not! If you want to show it, then good for you and format as you please and don’t forget to set the field to read only. If you don’t like this, then a) set the text color to white b) remove the borders of the text box c) set the field to read only. That way people shouldn’t be able to see it or interact with it. You will see why you need this field on the form in the next step.
- Select the field and then open up ‘Manage Rules’ within InfoPath.
- Right click on the field on the input form and click Text Box properties.
- Click the Advanced tab and add a ScreenTip label. We chose ‘SPGroup’. For those of you that are still wondering why we had to add the field to your input form, InfoPath won’t allow a ScreenTip label unless the control is actually on the input form.. and that ScreenTip is the primary reference in the code below.
- Publish the form.
- Click ‘New’ on the list or library.
- Edit the SharePoint page and add a Script Editor Web Part. If you are using SharePoint 2010, then add a Content Editor Web Part and apply formatting as necessary.
- Add the below code to the script editor and save.
You’re done! You can now use this SharePoint Group to apply formatting, validation or action rules to your other fields within InfoPath. Enjoy!