How to get UserID based on old email, if user changes his email

%3CLINGO-SUB%20id%3D%22lingo-sub-2081815%22%20slang%3D%22en-US%22%3EHow%20to%20get%20UserID%20based%20on%20old%20email%2C%20if%20user%20changes%20his%20email%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2081815%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20guys%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20I%20have%20a%20situation%20to%20get%20userid%20based%20on%20email%20address.%20I%20have%20a%20user%20email%20address%20which%20was%20already%20stored.%20Now%20the%20user%20changed%20his%20email%20address.%20By%20sending%20the%20old%20email%20address%20how%20to%20get%20the%20userid%20or%20can%20i%20get%20the%20new%20email%20address%20of%20the%20user%20by%20sending%20old%20email%20address.%3C%2FP%3E%3CP%3Ecode%20which%20i%20used%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20customerid_d%20%3D%20%24.Deferred()%3B%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20prefix%20%3D%20%3CSPAN%20class%3D%22hljs-string%22%3E%22i%3A0%23.f%7Cmembership%7C%22%3C%2FSPAN%3E%3B%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20Email%20%3D%20prefix%20%2B%20Email%3B%0A%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20customerid_url%20%3D%20_spPageContextInfo.webAbsoluteUrl%20%2B%20%3CSPAN%20class%3D%22hljs-string%22%3E%22%2F_api%2Fweb%2Fsiteusers(%40v)%3F%40v%3D'%22%3C%2FSPAN%3E%20%2B%20%3CSPAN%20class%3D%22hljs-built_in%22%3EencodeURIComponent%3C%2FSPAN%3E(Email)%20%2B%20%3CSPAN%20class%3D%22hljs-string%22%3E%22'%22%3C%2FSPAN%3E%3B%0AgetData(customerid_url%2C%20customerid_d%2C%20%3CSPAN%20class%3D%22hljs-literal%22%3Efalse%3C%2FSPAN%3E).done(%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Edata%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Evar%3C%2FSPAN%3E%20result%20%3D%20data.d%3B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Eif%3C%2FSPAN%3E%20(result%20!%3D%20%3CSPAN%20class%3D%22hljs-literal%22%3Eundefined%3C%2FSPAN%3E%20%26amp%3B%26amp%3B%20result%20!%3D%20%3CSPAN%20class%3D%22hljs-string%22%3E%22%22%3C%2FSPAN%3E%20%26amp%3B%26amp%3B%20result%20!%3D%20%3CSPAN%20class%3D%22hljs-literal%22%3Enull%3C%2FSPAN%3E)%20%7B%0A%20%20%20%20%20%20%20%20id%20%3D%20result.Id%3B%0A%20%20%20%20%7D%0A%7D)%3B%0A%0A%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-title%22%3EgetData%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Eurl%2C%20d%2C%20%3CSPAN%20class%3D%22hljs-keyword%22%3Easync%3C%2FSPAN%3E%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20%24.ajax(%7B%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3Eurl%3C%2FSPAN%3E%3A%20url%2C%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3Emethod%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-string%22%3E%22GET%22%3C%2FSPAN%3E%2C%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3Easync%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-keyword%22%3Easync%3C%2FSPAN%3E%2C%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3Eheaders%3C%2FSPAN%3E%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-string%22%3E%22Accept%22%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-string%22%3E%22application%2Fjson%3B%20odata%3Dverbose%22%3C%2FSPAN%3E%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3Esuccess%3C%2FSPAN%3E%3A%20%3CSPAN%20class%3D%22hljs-function%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Efunction%3C%2FSPAN%3E(%3CSPAN%20class%3D%22hljs-params%22%3Edata%3C%2FSPAN%3E)%20%3C%2FSPAN%3E%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20d.resolve(data)%3B%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%3CSPAN%20class%3D%22hljs-attr%22%3Eerror%3C%2FSPAN%3E%3A%20OnError%0A%20%20%20%20%7D)%3B%0A%20%20%20%20%3CSPAN%20class%3D%22hljs-keyword%22%3Ereturn%3C%2FSPAN%3E%20d.promise()%3B%0A%7D%3C%2FPRE%3E%3CP%3EPlease%20help%20me%20to%20find%20a%20solution%20for%20this.%20Thank%20you.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hello guys,

                  I have a situation to get userid based on email address. I have a user email address which was already stored. Now the user changed his email address. By sending the old email address how to get the userid or can i get the new email address of the user by sending old email address.

code which i used:

 

var customerid_d = $.Deferred();
var prefix = "i:0#.f|membership|";
var Email = prefix + Email;
var customerid_url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/siteusers(@v)?@v='" + encodeURIComponent(Email) + "'";
getData(customerid_url, customerid_d, false).done(function(data) {
    var result = data.d;
    if (result != undefined && result != "" && result != null) {
        id = result.Id;
    }
});

function getData(url, d, async) {
    $.ajax({
        url: url,
        method: "GET",
        async: async,
        headers: {
            "Accept": "application/json; odata=verbose"
        },
        success: function(data) {
            d.resolve(data);
        },
        error: OnError
    });
    return d.promise();
}

Please help me to find a solution for this. Thank you. 

0 Replies