troubleshooting Question

SP - SPServices get user based on email fails.

Avatar of Fredd
Fredd asked on
JavaScriptMicrosoft SharePoint
1 Comment1 Solution144 ViewsLast Modified:
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
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros