gpt4 book ai didi

javascript - Sharepoint-2013 用活跃用户部门填充字段

转载 作者:行者123 更新时间:2023-12-03 04:24:32 25 4
gpt4 key购买 nike

我有一些代码可以在 SP PeoplePicker 中查找用户并返回用户的部门。

我想要实现的是自动填充当前用户的部门字段,因为我不想要 peoplepicker 字段。当前用户数据应该是可检索的,或者我应该能够在没有 peoplepicker 字段的情况下通过 peoplepicker 进行搜索。

因此,我将以下脚本添加到内容编辑器中:

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>

<script>
$(document).ready(function()
{
var PeoplePicker = $("div[title='test_column']");
var PeoplePickerTopId = PeoplePicker.attr('id');
var ppobject = SPClientPeoplePicker.SPClientPeoplePickerDict[PeoplePickerTopId];

ppobject.OnValueChangedClientScript = function(elementId, userInfo){getUserData()};
});

function getUserData()
{
//Set variables
var UserDept;
var i;
var _PeoplePicker = $("div[title='test_column']");
var _PeoplePickerTopId = _PeoplePicker.attr('id');
var ppobject = SPClientPeoplePicker.SPClientPeoplePickerDict[_PeoplePickerTopId];

// Call GetAllUserInfo to read PeoplePicker entries
editorsInfo = ppobject.GetAllUserInfo();

// Set Customer Info
if(editorNames!= null)
{UserDept = editorsInfo[0].EntityData.Department;}

$("input[title='Department']").val(UserDept)
}
</script>

请注意,我无权访问 Sharepoint Designer。我试图仅从 WebView 中使其正常工作。

此外,如果答案需要 AJAX 或从 httpget 帖子返回值,您能否详细回答一下,因为我以前从未使用过 AJAX,并且在从网络服务器接收响应方面经验有限。

提前致谢!

最佳答案

您可以使用 SPServices Jquery。只需下载最新的即可。您使用的是 Sharepoint 2013,因此请使用脚本编辑器而不是内容编辑器。下面是我经常使用的脚本并且运行良好。

<script type="text/javascript" src="/your path to JS/SiteAssets/JS/jquery-3.1.1.js"></script>  
<script type="text/jscript" src="/your path to JS/SiteAssets/JS/jquery.SPServices.min.js"></script>

<script type="text/javascript">

$(document).ready(function() {

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


$("input[title*='Department']").val(UserDept); // For assigning to SharePoint column named 'Department'

$("#txtDept").val(UserDept); // For assigning to textbox


});

</script>

关于javascript - Sharepoint-2013 用活跃用户部门填充字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43793700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com