Infopath List Form – hide/disable fields based on SharePoint group membership

As we know in SharePoint 2010 we can customize list form using Infopath 2010. With Infopath 2010 we will get some advantages of more flexible look and feel, data validation/rules as well as web services invocation in the form of data connection without writing any single of code as in fact Infopath list form does not support code behind.

In this post I will show how to use Infopath data connection to build rules for hiding/disabling fields based on the SharePoint group membership of current user. In my case I would like to disable the Approval field as shown below for any users that are not member of  a SharePoint group called Form Administrator.


Here is my steps to achieve the goal:

  1. The first very step obviously is clicking the Customize Form on the ribbon to edit the form in Infopath Designer. I wouldn’t go to any detail of how to build a list form using Infopath 2010 as there are already a lot of posts about the topic for example this msdn article.

  2. Adding 2 received from SOAP Web Services data connections to the forms, again there are a lot of articles about this topic, so I wouldn’t go into any detail such as this one.
    • GetUserProfileByName in http://<server-name>/_vti_bin/UserProfileService.asmx. Tick Automatically retrieve data when the form opened.
    • GetGroupCollectionFromUser in http://server-name/_vti_bin/UserGroup.asmx (put a sample value, of an existing account such as contoso\account_name). Untick automatically retrieve data when the form opened.

  3. Save the form as source files as we are going to modify the xml schema of the GetGroupCollectionFromUser data connection. The reason why we need to do this is that the generated data connection doesn’t display the returned fields. As shown in the picture  that the dataFields  children elements only contain userLoginName which is not correct.
    To save the form as sources go to Files -> Publish as shown below then  click Export Source Files on the next window. The exported files would look like in the picture. It consists of infopath definition file (manifest.xsf), xml schemas of all data connections (.xsd files), some xml files that contain sample data of the data connections and an xsl file (view.xsl) used for form rendering. In our case we only focus on GetGroupCollectionFormUser.xsd (the xml schema for GetGroupCollectionFromUser data connection).

  4. Modify the GetGroupCollectionFromUser1.xsd, make sure close the Infopath Designer before editing. I found this approach from Sumit’s SharePoint blog, he explained how to correct the xsd in the ‘Correcting the xsd for the Return Fields’ section in his post. To summarize his approach basically, we need to add this below type definition
    <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>

    below this line (at the 2nd line of the file)

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

    Then find this below

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

    Replace it with this:

      <s:element name="GetGroupCollectionFromUser" type="tns:GetGroupCollectionFromUserType">
  5. Create a rule to invoke GetGroupCollectionFromUser web services method. As the method is not invoked when the form is opened, we need to invoke the method after the GetUserProfileByName invocation finished. To do this, right click on the manifest.xsf and choose Design. Choose GetUserProfileByName data connection and apply rules on the PropertyData field as display in the picture.

    The rule condition is Name=”AccountName”, rule type is Action. The rule actions are:

    1. Set field’s value: the userLoginName of the GetGroupCollectionFromUser’s queryFields to the Property value AccountName from the GetUserProfileByName.  This blog shows how to set the property value (please follow steps 7 – 10)
    2. Query for data: GetGroupCollectionFromUser. (no need screen shot for this :) )

  6. Create a formatting rule for the field (in my case approval field) that we want to disable/hide if current user is not member of a SharePoint Group. Put a condition as below, where The Form Administrator is the SharePoint Group Name.

    And the any occurrence & number of occurrence of Name is the SharePoint groups’ name retrieved from the dataFields of GetGroupCollectionFromUser data connection below, in other words the rule check if any of the groups’ name is Form Administrator or no SharePoint groups found associated with the current user, if condition met, disable the field.

  7. And finally publish the form

Please feel free to give me feedback if there is better approach.

20 thoughts on “Infopath List Form – hide/disable fields based on SharePoint group membership

  1. Hello there,
    I’ve been following this guide all day to try and do something similar for a ticketing system I have built up at work. I’ve gone through it two or three times and the only bit that I can see is different is when I get to the point of creating the ‘Hide this control’ conditions.
    In your image above you have the option of “Any occurrences of names…” and “Number of occurrences…” but two things:
    1) I cannot see the end of the rules
    2) In my Infopath 2010 I cannot see those options to use as conditioning. Would you be able to elaborate a bit more on how to set the conditioning to use these? It’s either a software issue, or something I’ve overlooked as my eyes are now quite blurry!
    Thanks very much for the guide!

    – Danoni

    Daniel Laksana Reply:

    Hi, You will see the choices on the Select a field or A group windows (on my last screen shot)

  2. PS: I cannot go with code, I have to do it from rules

    Daniel Laksana Reply:

    Yes, you are right. Infopath ListForm doesn’t support code as I mentioned in the article. And as shown in the post, I did the hide/disable field just by rules.

  3. The walk though is great until the end! It cant get it to check the group names. It only checks against the current user name.

    Daniel Laksana Reply:

    I am sure you missed the 4th step to modify the xml schema of GetGroupCollectionFromUser1.xsd. Otherwise you will only have userLoginName on the dataconnection as shown on a snapshot on the 3rd step.

  4. I found it easier to do, GetGroupCollectionFromUser – Name , and compare it to the name of the Group using contians and does not contain. I worked great for me!

    Matt Reply:

    This did it for me, just to reiterate I was having issues because most of the site members are in multiple groups or at least the ones that require certain access. Choose “Any occurrence of Group” contains “Desired Group Needing Access” worked for me, thank you!

  5. i am unable to get the current user to the text box ecept mine which is have given as default while creating this service. Can you please guide me on the same.

  6. Issue resolved. Hoever, the conditional formatting rule is not working. I am printing the user info and group info to the page, so I know it is being populated. The field is disabled no matter which user account I login with. Thoughts?

  7. I can’t get it working, when I publish and try to load the form in the web browser I get an error saying that couldn’t connect to the web service and checking logs it says that Infopath tried to perform an unathorized operation.

    Any Ideas???

  8. Instructions were great, thank you. But when I go to add an item, the field is still visible/active, until I actually change the value, at which point it becomes greyed out/hidden. Any suggestions?

  9. Hey i spend 4-5 hours with it. no success…… i found that any thing i do… the dataconnection for group was always querying using the sample value initially set.

  10. Thank you for your article but i’ve a problem. Sorry for my english but il ‘d try to explain :

    il think that rules on the propertyData’s GetUserProfileByName doesn’t invoke GetGroupColletionFromUser. The value in GetUserProfileByName return the AccountName, it’s ok, but actions in his propertydata rules don’t execute. I’ve tried to call simple action (set field’s value “abc” to ‘test” ) and the field “abc” is still empty.

    Do u have some ideas ? TY

  11. I found I was having trouble setting the LoginName for step 5a. So went with concat(“YOURDOMAIN\”, userName()) instead and that started pulling the right groups for my form.

  12. I love this solution! But I stucked at step 6.
    Im using the german vers. of infopath, not a real problem, but I cant get the “of occurrence of Name” condition. Im using the “GetGroupCollectionFromUser” -> dataFields ->……->Groups -> Group-> :Name and is not equal to “Members of IT” (thats the name of my SP-Group)
    so mb u might help me? :)

    Daniel Laksana Reply:

    Please click on the last screen shot. you will see that option.

  13. Hi there,
    I have built an infopath form that I am trying to restrict an approval drop down. I did the instructions as stated, yet the field is greyed out regardless of whether I put myself in the group or not. Can you help? Infopath 2010, SP 2013 enterprise.