Example for GetUserLoginFromEmail?

Jul 11, 2012 at 2:21 PM

Here's my attempt (which fails):

	function getUserLoginFromEmail(strEmail) {
		$().SPServices({
			operation: 'GetUserLoginFromEmail',
			emailXml: strEmail,
			async: false,
			completefunc: function (xData, Status) {
				alert(xData.responseText);
	                }
		});
	}

Coordinator
Jul 11, 2012 at 2:28 PM

What is the failure? What values are you passing in?

M.

Jul 11, 2012 at 4:30 PM

I did not understand that emailXml must be an XML string. I was passing the email address. So, instead of my "jsmith@whatever.com" you have to pass something like:

      emailXml: "<Users><User Email='" + strEmail + "'/></Users>",

I found that in another post.

Then, you must extract the value(s) you want. Something like:

      completefunc: function (xData, Status) {
        $(xData.responseXML).find("User").each(function() {
          var passBack = $(this).attr("Login");
        }); 

Now, the reason this was important for me is this: I had developed a nice scheme that "validated" a list of users (looked them up via one of your profile access methods). I was given email addresses to work with, so I carved off the login part of that and submitted it to my process. Worked 99.99% of the time. This failed when the name portion of an email address was not equivalent to the login value. It is the policy of this organization for those two values to be equivalent but, as I painfully found out, reality has another idea (this appears to have been the consequence of a marriage subsequent upon establishment of the woman's account).

I must now re-do this process to use the full email address and from that to retrieve the login value.

Coordinator
Jul 11, 2012 at 6:28 PM

Whenever you use an operation your anren't familiar with, I suggest that you read the associated documentation in the SDK. I have links to each page in the documentation pages for the individual Web Services, so it's an easy hop. There's not a lot of consistency in what all of the operations want to see, so I always check.

Exceptions can be the death of us, eh?

M.