SharePoint获取当前用户属性

发布于 2024-10-25 05:21:59 字数 682 浏览 1 评论 0原文

我有一个页面需要检索登录用户的部门。理想情况下,我希望能够通过 JavaScript SOAP CAML 查询来完成此操作。我有用户的 ID(我假设它兼作 GUID),因此检索与 ID 匹配的行似乎是一个简单的问题。

我正在考虑在 SOAP 中使用“GetUserProfileByIndex”或“GetUserProfileByGuid”函数,但我似乎找不到任何可靠的文档或使用它们的合适示例。我希望在 JavaScript 中做这样的事情 - (这不起作用):

 var userId = 194;
 "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
     <soapenv:Body> \
         <GetUserProfileByIndex  xmlns='http://microsoft.com/webservices/SharePointPortalServer/UserProfileService'> \
             <index>userId</index> \
         </GetUserProfileByIndex > \
     </soapenv:Body> \
 </soapenv:Envelope>";

I have a page that needs to retrieve the department for the logged-in user. Ideally I'd like to be able to do it through a JavaScript SOAP CAML query. I have the user's id (which I'm assuming doubles as the GUID), so it seems like a simple matter of retrieving the row that matches the ID.

I'm looking into using the 'GetUserProfileByIndex' or 'GetUserProfileByGuid' function in SOAP, but I can't seem to find any solid documentation or decent examples using them. I'm hoping to do something like this in JavaScript - (which isn't working):

 var userId = 194;
 "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
     <soapenv:Body> \
         <GetUserProfileByIndex  xmlns='http://microsoft.com/webservices/SharePointPortalServer/UserProfileService'> \
             <index>userId</index> \
         </GetUserProfileByIndex > \
     </soapenv:Body> \
 </soapenv:Envelope>";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

瞳孔里扚悲伤 2024-11-01 05:21:59

我建议您查看名为 SPServices 的 SharePoint 2007 和 2010 的 jQuery 库。 $().SPServices.SPGetCurrentUser 可以检索高效部门中的4行代码:

var thisDepartment = $().SPServices.SPGetCurrentUser({
fieldName: "Department",
debug: false
});

I recommend you check out the jQuery Library for SharePoint 2007 and 2010 called SPServices. $().SPServices.SPGetCurrentUser can retrieve the Department in an effecient 4 lines of code:

var thisDepartment = $().SPServices.SPGetCurrentUser({
fieldName: "Department",
debug: false
});
故事与诗 2024-11-01 05:21:59

我从未回答过自己的问题,但我设法想出了一个简单的解决方案。以下是我的处理方法

  1. 当用户登录时,有一个全局 JavaScript 变量,其中包括该用户的 ID, - __spUserId
  2. 用户配置文件列表可通过 SOAP 通过 CAML 查询访问,其标题为“用户信息列表”。
  3. 访问此列表时,您必须将顶级站点设置为指向 _catalogs 而不是列表(或任何确切的名称)。您可以通过添加元素 _catalogs \
  4. 由于它是以列表的形式访问用户配置文件列表而不是通过用户配置文件函数来执行此操作,因此将查询类型 (?) 设置为“GetListItems”

总体而言,这里是 SOAP 调用和 CAML 查询

$(document).ready(function() {
    var soapEnv =
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
            <soapenv:Body> \
                <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                    <listName>User Information List</listName> \
                    <topLevelSite>_catalogs</topLevelSite> \
                    <query> \
                        <Query> \
                            <Where> \
                                <Contains> \
                                    <FieldRef Name='ID' /> \
                                        <Value Type='Text'>"+_spUserId+"</Value> \
                                </Contains> \
                            </Where> \
                        </Query> \
                    </query> \
                    <viewFields> \
                        <ViewFields> \
                            <FieldRef Name='Name' /> \
                            <FieldRef Name='Department' /> \
                            <FieldRef Name='ID' /> \
                        </ViewFields> \
                    </viewFields> \
                    <query> \
                        <Query /> \
                    </query> \
                </GetListItems> \
            </soapenv:Body> \
        </soapenv:Envelope>";

    $.ajax({
        url: "/_vti_bin/Lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=\"utf-8\""
    });
});

I've never answered my own question, but I managed to come up with a simple solution. Here is how I went about it

  1. When a user is logged in, there is a global JavaScript variable that includes that user's ID, - __spUserId
  2. The user profile list is accessible via a CAML query through SOAP, it's titled 'User Information List'.
  3. When accessing this list, you have to set the top-level site to point to _catalogs instead of Lists (or whatever it is exactly). You do this by adding the element _catalogs \
  4. Since it is accessing the user profile list as a list and not through a userprofile function, set the query type (?) to 'GetListItems'

Overall, here is the SOAP call and CAML query

$(document).ready(function() {
    var soapEnv =
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
            <soapenv:Body> \
                <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                    <listName>User Information List</listName> \
                    <topLevelSite>_catalogs</topLevelSite> \
                    <query> \
                        <Query> \
                            <Where> \
                                <Contains> \
                                    <FieldRef Name='ID' /> \
                                        <Value Type='Text'>"+_spUserId+"</Value> \
                                </Contains> \
                            </Where> \
                        </Query> \
                    </query> \
                    <viewFields> \
                        <ViewFields> \
                            <FieldRef Name='Name' /> \
                            <FieldRef Name='Department' /> \
                            <FieldRef Name='ID' /> \
                        </ViewFields> \
                    </viewFields> \
                    <query> \
                        <Query /> \
                    </query> \
                </GetListItems> \
            </soapenv:Body> \
        </soapenv:Envelope>";

    $.ajax({
        url: "/_vti_bin/Lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=\"utf-8\""
    });
});
一指流沙 2024-11-01 05:21:59

您可能应该使用 GetUserProfileByName,网站集 ID 不能用于查找用户配置文件存储中的任何内容。

http://amitkumarmca04.blogspot.com/2008 /07/how-access-sharepoint-moss-user-profile.html

You should probably use GetUserProfileByName, site collection ids can't be used to lookup anything in the user profile store.

http://amitkumarmca04.blogspot.com/2008/07/how-access-sharepoint-moss-user-profile.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文