Link to home
Start Free TrialLog in
Avatar of 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 = ''; 
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

Avatar of Piotr Strycharz
Piotr Strycharz
Flag of Poland image

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