Thursday, February 18, 2016

Get the site user id by full name of the user

function GetUserIdByName(name) {
    var userId = "";
    $.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/SiteUsers?$Select=Id,Title&$filter=Title eq '" + name + "'",
        type: "GET",
        async: false,
        headers: {
            "accept": "application/json;odata=verbose",
            "content-type": "application/json;odata=verbose"
        },
        success: function(data) {
            userId = data.d.results[0].Id;
        },
        error: function(err) {
            console.log(JSON.stringify(err));
        }
    });
    return userId;
}

No comments:

Post a Comment

How to launch a document by clicking a link to the file?

Word: <a href='ms-word:ofe|u|path/to/web/word/document.docx'>Link to document</a> Excel: <a href='ms-excel:o...