我正在寻找一种方法来添加人选择器项目在线,就像项目信息表单上的所有者字段。但是我想显示我的组织AD (Office 365用户)中的所有用户。
许多文章和SO问题都指向这个链接,https://code.msdn.microsoft.com/sharepoint-2013-use-the-57859f85,但是这个链接不再指向任何有用的资源。
在项目在线中没有选项可以通过自定义字段添加。2018年有一个用户语音功能请求,但似乎微软没有实现这样一个常见的功能。
任何指导都非常感谢
我在我的GitHub上发布了一个答案,可以在这里找到
基本上你需要创建一个自定义字段,然后添加一个"内容编辑器"到页面(建议隐藏它)。将Javascript人员选择器的路径添加到内容编辑器中。在Javascript人员选择器中,在脚本的顶部,有一个针对自定义字段的数组。将文本替换为要调用的字段并保存。挑选人的人应该在那个时候工作。链接上有更详细的一步一步的说明。
以下脚本可在此视频后使用https://www.youtube.com/watch?v=cR0W4umH8ZU
<script>
//Set the following to be an array of fields you would like to change into a people-picker
//var targetFields = ['Project Sponsor'];
var targetFields = ['Customer Representative','Solution Architect'];
//safely load JQuery
if (typeof jQuery == 'undefined') {
var s = document.createElement("script");
s.src = '//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js';
if (s.addEventListener) {
s.addEventListener("load", function () { myJQueryCode() }, false);
} else if (s.readyState) {
s.onreadystatechange = function () { myJQueryCode() };
}
document.getElementsByTagName('head')[0].appendChild(s);
} else {
myJQueryCode();
}
function myJQueryCode() {
$(document).ready(function () {
var scriptRoot = _spPageContextInfo.siteAbsoluteUrl + '/_layouts/15/';
$.when(
$.getScript(scriptRoot + "clienttemplates.js"),
$.getScript(scriptRoot + "clientforms.js"),
$.getScript(scriptRoot + "clientpeoplepicker.js"),
$.getScript(scriptRoot + "autofill.js")
)
.done(function () {
window.console && console.log('Scripts loaded');
renderPeoplePickers();
})
.fail(function (message) {
window.console && console.error('Loading scripts failed: ' + message);
});
});
}
function renderPeoplePickers() {
for (fieldIndex = 0; fieldIndex < targetFields.length; fieldIndex++) {
$("input[type='text'][title='" + targetFields[fieldIndex] + "']").each(function () {
this.style.color = "green";
renderPeoplePicker(this);
window.console && console.log('PeoplePicker rendered: ' + targetFields[fieldIndex]);
});
}
}
function renderPeoplePicker(targetInput) {
var divPeoplePicker = document.createElement('div');
var idPeoplePicker = targetInput.id + '_PeoplePicker';
var targetValue = $(targetInput).attr('value');
divPeoplePicker.id = idPeoplePicker;
$(targetInput).parent().append(divPeoplePicker);
initializePeoplePicker(idPeoplePicker);
var newPeoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict[idPeoplePicker + '_TopSpan'];
$(targetInput).hide();
if (typeof targetValue !== "undefined") {
var selectedUsers = targetValue.split(";");
for(i=0;i<selectedUsers.length;i++){
if(selectedUsers[i] && selectedUsers[i] != "") {
newPeoplePicker.AddUnresolvedUser({
Key: selectedUsers[i],
DisplayText: selectedUsers[i]
}, true);
}
}
}
newPeoplePicker.OnControlResolvedUserChanged = function () {
if (this.TotalUserCount > 0) {
var fieldVal = '';
for(i=0;i<this.GetAllUserInfo().length;i++) {
//we have a resolved user
var resolvedUser = this.GetAllUserInfo()[i];
fieldVal = fieldVal + resolvedUser.DisplayText + ";";
}
//Set the underlying field value
$('input#' + (this.TopLevelElementId.split("_PeoplePicker_TopSpan")[0])).attr('value', fieldVal);
//If value has changed then mark the PDP dirty to enable save
//Thankyou to Martin Laukkanen (nearbaseline.com) for this fix!
if ($('input#' + (this.TopLevelElementId.split("_PeoplePicker_TopSpan")[0])).attr('origvalue') !== $('input#' + (this.TopLevelElementId.split("_PeoplePicker_TopSpan")[0])).attr('value')) {
WPDPParts[0].IsDirty = true;
}
} else {
//we have nothing - so clear out the target field
$('input#' + (this.TopLevelElementId.split("_PeoplePicker_TopSpan")[0])).attr('value', '');
}
}
}
// Render and initialize the client-side People Picker.
function initializePeoplePicker(peoplePickerElementId, defaultValue) {
var users;
if ((defaultValue != undefined) && (defaultValue != "")) {
users = new Array(1);
var defaultUser = new Object();
defaultUser.AutoFillDisplayText = defaultValue;
defaultUser.AutoFillKey = defaultValue;
//defaultUser.Description = user.get_email();
defaultUser.DisplayText = defaultValue;
defaultUser.EntityType = "User";
defaultUser.IsResolved = false;
defaultUser.Key = defaultValue;
defaultUser.Resolved = false;
users[0] = defaultUser;
} else {
users = null;
}
// Create a schema to store picker properties, and set the properties.
var schema = {};
schema['PrincipalAccountType'] = 'User';
//schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
schema['SearchPrincipalSource'] = 15;
schema['ResolvePrincipalSource'] = 15;
schema['AllowMultipleValues'] = true;
schema['MaximumEntitySuggestions'] = 50;
schema['Width'] = '360px';
// Render and initialize the picker.
// Pass the ID of the DOM element that contains the picker, an array of initial
// PickerEntity objects to set the picker value, and a schema that defines
// picker properties.
this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, users, schema);
}
</script>
来源:https://www.epmpartners.com.au/wp-content/uploads/2017/10/PdpPeoplePicker_Info.js