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:
- Creating a web service connection: New web service connection need to be created to obtain the group name thought the GetGroupCollectionFormUser service.
- Exporting the form: The form needs to be exported as we will apply some changes in one of the exported files.
- Updating the XSD file: Edit the GetGroupCollectionFormUser1.xsd file.
- 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.
- 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:
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:
- Get the group Name for the logged in user by creating an action when Form Load and querying the data connection:
- Set UserLoginNameValue from the GetGroupCollectionFromUser connection (as shown on the first image)
- Set the UserLoginName value with the current logged user AccountName.
- Get the group details by creating an action to query the GetGroupCollectionFormUser data connection.
- 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.
- 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.
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
Hi,
ReplyDeleteI 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