Security Trimming SharePoint 2010 InfoPath Form Fields

UPDATED for SharePoint 2013

Security Trimming InfoPath fields with SharePoint 2010 InfoPath Forms Services Based on SharePoint User Groups & Claims-Based Authentication
Infopath List Form – hide/disable fields based on SharePoint group membership
InfoPath: Displaying SharePoint Group List Using “GetGroupCollectionFromUser” method

Additional info required for 2013:
SharePoint 2013, InfoPath and Claims – GetUserProfileByName

All of the above sources had most of details, but some steps seemed to be missing when I attempted to follow them. However, I would not have been able to figure it out without them.

For 2013, you’ll need to create a Secure Store Service connection. See the information listed under “Additional info required for 2013” on how to do this.

Create the Data Connection

On a form that has been created and published back to SharePoint, create the data connection. Create a new connection to receive data from a SOAP Web Service.

Connect to https://WEBAPP/sites/SITECOLLECTION/_vti_bin/usergroup.asmx.

The operation we need is GetGroupCollectionFromUser.

Set the sample value for the user login name; this is an actual login – probably yours. The web application in my example has Claims Based Authentication, so instead of just domain\username, I needed to enter “i:0#.w|domain\username”.

Save and publish the form.

Modify the Schema

The schema, as it is now, can’t be used. We need to modify it to add in the data fields.

Export the source files.

It’s helpful to make a new folder for just this form (we’ll delete it later.)

CLOSE INFOPATH AND OPEN THE FOLDER JUST CREATED. The file we need to modify should be called GetGroupCollectionFromUser1.xsd. Open it with notepad.

After the line:

<s:import namespace=""></s:import> 

Add the following:

<s:complexType name="GetGroupCollectionFromUserType">
      <s:element minOccurs="0" maxOccurs="1" name="userLoginName" type="s:string"/>
      <s:element minOccurs="0" maxOccurs="1" name="Groups">
            <s:element maxOccurs="unbounded" name="Group" >
                <s:attribute name="ID" type="s:unsignedShort"></s:attribute>
                <s:attribute name="Name" type="s:string"></s:attribute>
                <s:attribute name="Description" type="s:string"></s:attribute>
                <s:attribute name="OwnerID" type="s:unsignedByte"></s:attribute>
                <s:attribute name="OwnerIsUser" type="s:string"></s:attribute>

Find this:

<s:element name="GetGroupCollectionFromUser">
       <s:element minOccurs="0" maxOccurs="1" name="userLoginName" type="s:string">

And replace it with this:

<s:element name="GetGroupCollectionFromUser" type="tns:GetGroupCollectionFromUserType">

Save and close the xsd file.

Finish the form design

In the folder with the modified schema, right-click manifest.xsf and design.

*If you don’t use a data connection library, you can skip this step. File name in the DataConnection library would be GetGroupCollectionFromUser.udcx.

** UPDATE for 2013 – You’ll HAVE to use a data connection file and update the file to use the secure store service: <udc:Authentication><udc:SSO AppId=’InfoPathWebService’ CredentialType=’NTLM’ /></udc:Authentication>

Be sure to change the approval status of the connection file to approved.

Form Load Rule

Create a new rule to execute on Form Load.

Add action “Set a field’s value”. Set the field, userLoginName, in GetGroupCollectionFromUser to userName()

** UPDATE for 2013 – Contrary to the above articles, setting the query field to substring-after(userName(), “0#.w|”) did NOT work for me. I had to set it back to userName() – but you may have to try it either way.

Add the action “Query for data”.

Data connection will be GetGroupCollectionFromUser.

Field Rule

Select the field to be secured. Add a new formatting rule.

The condition is where All occurrences of Name (these are the groups the user interacting with the form belongs to) are not equal to the SharePoint Group with permissions.

Save and publish the form.

Update: I had a scenario where we were showing a field (warning you don’t have rights to do this) only if the user was not member of the contributors group. In that case the condition was where “Any occurrence of Name” is equal to “SharePoint Group” than hide control.



2 Responses to Security Trimming SharePoint 2010 InfoPath Form Fields

  1. Titan Gel says:

    An impressive share! I have just forwarded this onto a coworker who had been doing a little homework on this.

    And he actually ordered me lunch simply because I stumbled upon it for him…
    lol. So let me reword this…. Thank YOU for the meal!! But yeah,
    thanx for spending time to talk about this subject here on your site.

  2. Definitely agree with this – its not always easy to get points like this around but
    you have performed an admirable job to your audience

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: