Getting the group Name of the current user in Info path forms

Sometimes, it is useful to get the group name of the current user in order to create rules based on that group, i.e: if we want to manage the permissions within the form through views depending on groups.


The following example shows how to get the group name of the current user

I have divided the steps in 4 main sections:
  1. Creating a web service connection:  New web service connection need to be created to obtain the group name thought the GetGroupCollectionFormUser service.
  2. Exporting the form:  The form needs to be exported as we will apply some changes in one of the exported files.
  3. Updating the XSD file: Edit the GetGroupCollectionFormUser1.xsd file.
  4. Creating rules to manage the permissions within the form: The form permissions will be managed through rules created in the Form Load. Users will see different form views depending on the groups they belong to.

    Creating a web service connection:

    • Manage Data Connections -> Add -> Receive Data -> SOAP Web Service.
    • Include the following URL:
      • http://servername/_vti_bin/usergoup.asmx?WSDL

    • Click Next and select GetGroupCollectionFromUser
    • Click on Set Sample Value and Insert an user Administrator as following : Domain\User.
    • Uncheck the "Automatically retrieve data when the form is opened" tick box.
    • The new connection will look as following:
    GetGroupCollectionFromUser connection

    According to the image above there is no information about the group, the unique accessible information is the UserLoginName. We will export the form and apply some changes in one XSD file to obtain the group details.

    Exporting the form:
    • File -> Publish -> Export Source Files
    • Create a new folder called "Export" to save the exported files.

    Updating the XSD file

    • Close the form and go to the Export folder.
    • Open in edit mode the GetGroupCollectionFormUser1.xsd file (You can use notepad)
    • Find this line:    <s:import namespace="http://www.w3.org/2001/XMLSchema">
    • Add this code after the above line.
    <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>
    • Replace this code:
    <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>

    With this code: 
    <s:element name="GetGroupCollectionFromUser" type="tns:GetGroupCollectionFromUserType">
    </s:element>

    • Open the manifest XSD file as Design:


    • Check the GetGroupCollectionFromUser connection now, the details of groups are now in the connection:
    Connection

    • Overwrite your previous form with the one that you already have opened

    Creating rules to manage the permissions within the form
    • Get the group Name for the logged in user by creating an action when Form Load and querying the data connection:
      1. Set UserLoginNameValue from the GetGroupCollectionFromUser connection (as shown on the first image)
      2. Set the UserLoginName value with the current logged user AccountName.
      3. Get the group details by creating an action to query the GetGroupCollectionFormUser data connection.
    Setting user login Name




    Getting the current logged user account name




    Your "Get the group Name" rule will look like as following:

    Get the group name


    • Create different views within the form for different groups, i.e.: one read only view for the "Visitors" group.
    •  Add Actions in the "Form Load" to switch views depending on the current user group.
              The following example shows how set up the rules for users belonging to the Visitors group, in this case the Visitors group will have Read Only access to the form.
    1. Add the condition by Selecting the Name in the GetGroupCollectionFromUser connection, and selecting Any occurrence of Name. This means that the condition complies if the current user is member of "Visitors", regardless if the user is member of more groups.
      Creating rules

           2.  Type the group name "Visitors" in the other part of the condition, and set the condition "is equal to".
           3. Add the action "Switch views" and select the Read Only view





      Comments

      1. Hi,
        I have this error ...
        how can I solve that?
        ---------------
        Warning
        Error processing the form.
        Click on OK to continue filling in the form. You may want to check possible errors in the form data.
        HIDE DETAILS OF ERROR
        Error trying to connect to a web service.

        An entry has been added to the server's Windows event log.
        Registration ID: 5566

        Correlation ID: dbaf6a9e-3918-901c-84d5-c9974814d40e

        ReplyDelete

      Post a Comment

      Popular posts from this blog

      How to convert fields in lower case/upper case within Info path forms

      How to auto save a browser enabled info path form every X minutes in Sharepoint 2007, 2010 and 2013

      Auto-populate the person/Group picker from the current user on InfoPath 2007/2010/2013