因此,我有一个SP Online列表,每个用户都可以提交其条目。我有一个默认列“ created by”,其中列出了提交条目的用户。我想另设两列,以便从用户帐户中自动复制用户部门和职务。我该怎么办?
答案 0 :(得分:0)
首先,您需要在SharePoint页面上加载“ SP.UserProfiles.js,SP.Runtime.js和SP.js” js文件,然后使用以下代码段加载这些文件, $(document).ready(function(){
var scriptbase = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/";
$.getScript(scriptbase + "SP.Runtime.js",
function () {
$.getScript(scriptbase + "SP.js",
function () {
$.getScript(scriptbase + "SP.UserProfiles.js", GetUserInformation);
});
});
});
var userProfileProperties;
function GetUserInformation() {
// Get the current client context.
var clientContext = SP.ClientContext.get_current();
//Get Instance of People Manager Class
var peopleManager = new SP.UserProfiles.PeopleManager(clientContext);
var targetUser = "domain\\userId";
userProfileProperties = peopleManager.getPropertiesFor(targetUser);
//Execute the Query.
clientContext.load(userProfileProperties);
clientContext.executeQueryAsync(onSuccess, onFail); }
function onSuccess () {
// get user information from userProfileProperties and set to your target column.
userProfileProperties.get_userProfileProperties()['Department'];
userProfileProperties.get_userProfileProperties()['SPS-JobTitle'];
//要做:列出项目替换操作 }
function onFail (sender, args) {
alert("Error: " + args.get_message());
}
参考:https://msdn.microsoft.com/en-us/library/office/jj679700.aspx
方法2:工作流程
当用户添加/编辑项目时,我们触发工作流将用户的部门/职位名称复制到目标列