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.

infopath_approval_field

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:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="userLoginName" type="s:string"/>
          <s:element minOccurs="0" maxOccurs="1" name="Groups">
            <s:complexType>
              <s:sequence>
                <s:element maxOccurs="unbounded" name="Group" >
                  <s:complexType>
                    <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>
                  </s:complexType>
                </s:element>
              </s:sequence>
            </s:complexType>
          </s:element>
        </s:sequence>
      </s:complexType>
    

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

    <s:import namespace="http://www.w3.org/2001/XMLSchema"></s:import>
    

    Then find this below

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

    Replace it with this:

      <s:element name="GetGroupCollectionFromUser" type="tns:GetGroupCollectionFromUserType">
     </s:element>
    
  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.

18 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

    [Reply]

    Daniel Laksana Reply:

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

    [Reply]

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

    [Reply]

    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.

    [Reply]

  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.

    [Reply]

    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.

    [Reply]

  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!

    [Reply]

    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!

    [Reply]

  5. 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?

    [Reply]

  6. 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???

    [Reply]

  7. 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?

    [Reply]

  8. 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.

    [Reply]

  9. 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.

    [Reply]

  10. 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? :)

    [Reply]

    Daniel Laksana Reply:

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

    [Reply]

  11. 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.

    [Reply]

Leave a Reply

Your email address will not be published. Required fields are marked *


8 + one =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">