1. 程式人生 > >Sharepoint Rest 根據user獲取UserId

Sharepoint Rest 根據user獲取UserId

client sid fail delegate har repo () point json

var finalusersId = "";
$.each(users, function () {
$.ajax({
url: webUrl + "/_api/web/siteusers(@v)?@v=‘"+encodeURIComponent(this.Key)+"‘",
type: "GET",
async: false,
headers: {
"Accept": "application/json;odata=verbose",
},
cache: false,
success: function (data) {
var result=data.d;
finalusersId=result.Id;
},
error: function (data) {

}
});
});

//根據用戶登錄名獲取ID

function getUserIdByLoginName(loginName) {
var context = new SP.ClientContext.get_current();
this.user = context.get_web().ensureUser(loginName);
context.load(this.user);
context.executeQueryAsync(
Function.createDelegate(null, ensureUserSuccess),
Function.createDelegate(null, onFail)
);
}
function ensureUserSuccess() {
alert(this.user.get_id())

}

Sharepoint Rest 根據user獲取UserId