troubleshooting Question

SP - SPServices get user based on email fails.

Avatar of Fredd
Fredd asked on
Microsoft SharePointJavaScript
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 = ''; 
var userlogin = getuserfromemail(email); 

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;
// 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); 
		$(x.responseXML).find("User").each(function() {
			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. 
    operation: "GetUserLoginFromEmail",
    emailXml: "<Users><User Email=''/></Users>",
        completefunc: function (xData, Status) {
        $(xData.responseXML).find("User").each(function() {
 return userlogin; 
} // getuseridfromemail

Open in new window

Piotr Strycharz
Software/web developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
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