Link to home
Start Free TrialLog in
Avatar of Fredd
Fredd

asked on

SP - SPServices get user based on email fails.

Environment SPO SCA access, etc
I'm trying to get the userlogin info based on their email address using JS - as below.  
I had problems getting the create.delegate approach to work so went to my old friend SPServices - The below gives me status  = error and if I examine
the xml string returned (x.responseText) I get Bad Request.
I swear I had this approach working on prem but can't access that today
Any ideas or trouble shooting ideas most welcome.  Normally if SPServices can't find a record, it returns Status  = Sucess but the each function
just doesn't fire.  Thanks in Advance.
 
function dowork() { 
var email = 'xxx@xxx.onmicrosoft.com'; 
var userlogin = getuserfromemail(email); 
alert(userlogin); 

}
function getuserfromemail(email) { 
// get userlogin from user email as recorded in systemLanguage
"use strict";
var e = "<Users><User Email='" + email + "'/><Users>";  // tried both ways 
var e = '<Users><User Email="' + email + '"/><Users>';  // this is the correct email - I've checked many times. 
var userlogin = null;
 alert(e);
// below  results in error status - Bad Request 
$().SPServices ( { 
	debug: true, 
	operation: "GetUserLoginFromEmail",
	emailXml: e, 
	async: false, 
	completefunc: function(x,status){ alert(status + "   status"); console.log(x); 
		console.log(x.responseText.text); 
		console.log(x.responseXML.xml);
		$(x.responseXML).find("User").each(function() {
		alert("each"); 
			var user = $(this); 
			userlogin = user.attr("Login")
			var userdn = user.attr("DisplayName"); 
			alert (userlogin + " " + userdn); 
			}) // each
}   // completefunc
}); // spservices 
// below an example from jack which works. 
/*
$().SPServices({
    operation: "GetUserLoginFromEmail",
    emailXml: "<Users><User Email='jack_harry@goodworld.net'/></Users>",
        completefunc: function (xData, Status) {
        $(xData.responseXML).find("User").each(function() {
                    $(this).attr("DisplayName");
                })
        }
});
*/
 return userlogin; 
} // getuseridfromemail

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Piotr Strycharz
Piotr Strycharz
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial