我已经尝试过在下面的rest调用中使用rest api,但是我没有获得employee id属性。并且要明确我不希望用户名。网址:_spPageContextInfo.webAbsoluteUrl +“ /_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='” + userID +“'”,
默认情况下,AD的employeeID不在SharePoint用户配置文件属性中,请创建一个新的用户属性并映射到该属性,然后在SharePoint和AD之间进行完全同步:
Sharepoint: How to display additional fields in User profile page
然后使用下面的代码片段获取当前用户的员工ID:
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type='text/javascript'>
var workEmail = "";
var EmployeeID = "";
var Division = "";
var userDisplayName = "";
var AccountName = "";
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
headers: { Accept: "application/json;odata=verbose" },
success: function (data) {
try {
//Get properties from user profile Json response
userDisplayName = data.d.DisplayName;
AccountName = data.d.AccountName;
var properties = data.d.UserProfileProperties.results;
console.log(properties)
for (var i = 0; i < properties.length; i++) {
var property = properties[i];
if (property.Key == "WorkEmail") {
workEmail = property.Value;
}
if (property.Key == "EmployeeId") {
EmployeeID = property.Value;
}
}
$('#AccountName').text(AccountName);
$('#userDisplayName').text(userDisplayName);
$('#EmployeeID').text(EmployeeID);
$('#workEmail').text(workEmail);
} catch (err2) {
//alert(JSON.stringify(err2));
}
},
error: function (jQxhr, errorCode, errorThrown) {
alert(errorThrown);
}
});
</script>
<h2><strong>Employee Details</strong></h2>
<br />
AccountName <span id="AccountName"></span><br/>
DisplayName <span id="userDisplayName"></span> <br/>
EmployeeID <span id="EmployeeID"></span><br/>
Email Address <span id="workEmail"></span> <br/>