Checking if a user is a member in a SharePoint group within web InfoPath 2010 forms
2016-03-25 09:15
676 查看
首先感谢原作者,但是他有两个错误的地方,导致了一天的时间都用在了上面,我这里重新整理下,并且特别标注了原文错误的地方。
原文链接http://www.hishamqaddomi.ca/spg/index.php/sharepoint-2010/infopath-2010/65-checking-if-a-user-is-a-member-in-a-sharepoint-group-within-web-infopath-2010-forms
Checking
if a user is a member in a SharePoint group within web InfoPath 2010 forms
Published on Wednesday, 02 January 2013 07:55
I know that there are so many articles about this topic, but many of them were too complicated for many people to understand and some of them has spelling or text encoding problems. I hope this will be clearer to everyone and eliminates the errors in the others.
First of all, you need to create a group and make sure that it can be viewed by Everyone.
You need to create to fields to grab the username and to check if he is a member in the specified group. I created them in a separate section and called them CurrentUser and IsGroupMember.
Now from the Data tab click Data Connection button.
Now we need to add a data connection from here to the user profiles service. Click Add… from the Connections box.
Select to “Receive Data” from your connection
Choose the “SOAP Service” from the wizard.
In the next dialogue box add the path to your sites UPS, it will be like this: http://[YourURL]/_vti_bin/userprofileservice.asmx
It will grab the full URL by itself.
When the service is connected, it will ask for the query function. For our purposes, we will use GetUserProfileByName, like in the following screen
shot.
In the next screen just click “Next”.
In the next screen just click “Next”.
If you want to change the connection name, do it from the next screen, else just click finish.
Go to the field we created called “CurrentUser”, right click, choose properties from the menu. Near the value field click the fx button
to insert a formula.
Click “Insert Field or Group”.
From the dropdown, choose the user profiles data connection we created (GetUserProfileByName), expand data fields, expand tns:GetUserProfileByNameResponse
> GetUserProfileByNameResult > PropertyData > Values > ValueData and choose Value from the list. Then click Filter
Data…
A Filter Data dialogue box will appear click Add…
From Specify Filter Conditions change the first drop down from value to Select a Field or Group
Choose the data source GetUserProfileByName Expand: dataFields
> tns:GetUserProfilesByNameResponse > GetUserProfilesByNameResult > PropertyData > Name then click OK
From the Specify Filter Conditions the last drop down choose to type text and type: AccountName, exactly as you see it. Do not add quotes the
system will add them.
Click OK on all open boxes.
Now we need to connect to the group web service. We will follow the same add data connection we did earlier for the User Profiles service, this time the URL of the service will be like: http://[YourURL]/_vti_bin/UserGroup.asmx
From the next dialogue box choose: GetUserCollectionFromGroup then click next.
In the next two Dialogue box click Set Sample Value…
Type the name of the group you need to check if the user is member in, and click OK.
In the next two Dialogue box click Set Value…
Type the name of the group you need to check if the user is member in, and click OK.
Now from the InfoPath File menu, choose Publish from
the right bar then click Export Source Files.
Save the files to the folder of your choice.
From the files choose GetUserCollectionFromGroup1.xsd and open it with your preferred text editor. I personally opened it with Notepad.
In the code file locate this code.
<s:import namespace="http://www.w3.org/2001/XMLSchema"></s:import>
Type this snippet right under it:
<s:complexType name="GetUserCollectionFromGroupType"> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="Users"> <s:complexType> <s:sequence> <s:element maxOccurs="unbounded" name="User" > <s:complexType> <s:attribute name="Notes" type="s:string"></s:attribute> <s:attribute name="Name" type="s:string"></s:attribute> <s:attribute name="IsSiteAdmin" type="s:string"></s:attribute> <s:attribute name="Sid" type="s:string"></s:attribute> <s:attribute name="ID" type="s:string"></s:attribute> <s:attribute name="LoginName" type="s:string"></s:attribute> <s:attribute name="Email" type="s:string"></s:attribute> <s:attribute name="IsDomainGroup" type="s:string"></s:attribute> </s:complexType> </s:element> </s:sequence> </s:complexType> </s:element> </s:sequence> </s:complexType>
In the same file locate this code:
<s:element name="GetUserCollectionFromGroup">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="groupName" type="s:string"></s:element>
</s:sequence>
</s:complexType>
</s:element>
Replace it with:
<!--<s:element name="GetUserCollectionFromGroup">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" type="s:string"></s:element>
</s:sequence>
</s:complexType>
</s:element>-->
<s:elementname="tns:GetUserCollectionFromGroup" type="tns:GetUserCollectionFromGroupType"></s:element>
注意:这个地方原作者写错了!!!!重要的事情说三次,这个地方原作者写错了,按照他写的这个来做,会一直报错,正确的写法是
<!--<s:element name="GetUserCollectionFromGroup">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="groupName" type="s:string"></s:element>
</s:sequence>
</s:complexType>
</s:element>-->
<s:element name="GetUserCollectionFromGroup" type="tns:GetUserCollectionFromGroupType" />
Save the file and close it. Right click “manifest.xsf” and choose “Design”.
Now you will notice that the GetUserCollectionFromGroup will look like this:
Right click the second field we created IsGroupMember and choose Properties.
From the properties box click fx button.
From the Insert Formula box click Insert
Function…
From the Insert Function box choose the count function
Now double click on the text that says double click to insert field between the parenthesis.
有错误:From the Select a Field or Group box, choose GetUserCollectionFromGroup from the drop down. Expand myFields
> queryFields > ns1:GetUserCollectionFromGroup > Users > User and choose :LoginName from the list, then click Filter
Data…
注意,这个地方作者写的不对,重要的事情说三遍,这个地方应该是从dataFields而不是queryFields取loginName,
From the Filter Data box, click Add... to add a new filter.
From the Specify Filter Conditions dialogue go to the last drop down, choose Select
a field or group… option
From the Select a Field or Group dialogue, choose “Main”
from the drop down and navigate to CurrentUser field that we created earlier. Click OK.
Now your filter should look like this:
Click OK to all dialogue boxes.
This will grab the username you are logged in with and will check if you are a member in the group you specified. If you are a member in that group the field IsGroupMember will
return 1, otherwise it will return 0.
Now you can create all types of rules to show/hide section, switch views… etc. based on the logged user group
相关文章推荐
- SharePoint 2010企业应用解决方案
- SharePoint 2010 开发人员学习指南
- sharepoint 2010 从PeopleEditor控件中取出多用户,并返回SPFieldUserValueCollection
- 在文档库中向指定的文件夹添加文档
- 设置sharepoint宿主网站
- sharepoint 2010 判断当前用户是否为用户组成员
- SharePoint 2010 IT Professional--巧用Calendar List
- SharePoint 2010的Document Library Upload Multiple Documents功能失效的解决方案
- SharePoint 2010 IT Professional--Document Version
- 妙用“Check out”与“Check In”
- 小议:上传Document自动Checked out与Existing的Document被Checked out的区别
- SharePoint 2010 IT Professional -- Recycle Bin
- SharePoint 2010 IT Professional-- Import Term Set
- SharePoint 2010 Configuration Failed
- SharePoint 2010 升级到SharePoint 2013的流程
- SharePoint 2010 IT Professional-- Quota Templates
- SharePoint 2010 IT Professional--如何创建My Site
- 小议:SharePoint 2010 Upgrade时,Restore Content Database 失败的解决方案?
- sharepoint 2010 sharepoint 2007迁移到sharepoint 2010方法
- sharepoint 2010 在自定义列表的字段上增加功能菜单