SharePoint 列表自动填充用户名

问题描述 投票:0回答:1

我想知道在 SharePoint 列表中,当有人创建新项目时,他们的用户名如何自动填充?分享点列表中是否已经内置了功能?

谢谢!

sharepoint sharepoint-list auto-populate
1个回答
0
投票
peoplepicker (

JQuery) 中的 GetCurrentUser ($().SPServices.SPGetCurrentUser),使用内容编辑器添加 NewForm.aspx。

(function () {
    var ctx = {};
    ctx.Templates = {};
    ctx.Templates.Fields = {
        'Applicant': {
            'NewForm': renderAssignedTo
        }
    };
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(ctx);
})();

function renderAssignedTo(ctx) {
     var currentUser = $().SPServices.SPGetCurrentUser({fieldNames: ["Title", "Name"]});
     var currentUserEntry = createUserEntity(currentUser.Name,currentUser.Title);
     //Set user default value
     ctx.CurrentFieldValue = [];   
     ctx.CurrentFieldValue.push(currentUserEntry);  
     return SPClientPeoplePickerCSRTemplate(ctx);
}

function createUserEntity(userLoginName,userDisplayName)
{
   return {
      Description: userLoginName,
      DisplayText: userDisplayName,
      EntityGroupName: "",
      EntityType: "",
      HierarchyIdentifier: null,
      IsResolved: true,
      Key: userLoginName,
      MultipleMatches: [],
      ProviderDisplayName: "",
      ProviderName: ""
   };
}
© www.soinside.com 2019 - 2024. All rights reserved.