GetUserInfo to a variable

Feb 3, 2010 at 7:11 PM
Edited Feb 3, 2010 at 7:12 PM

Mark

I know I'm going to feel stupid asking this question but I can't take it anymore. All I want to do is assign the users email to a variable using the GetUserInfo service but the behavior I'm encountering is strange to say the least. On the fist pass through, the GetUserInfo retuns "underfined" for a variable value but later it successfully display the email value (using an alert to verify). Is there a scope issue with the variable? Here is the code.

$(document).ready(function(){
		$('a[href$=PPT.aspx]').click(function (){		
			submitListInfo();
			return false;
		});

		function submitListInfo(){
			var username 	=$().SPServices.SPGetCurrentUser();
			var usrEmail	=captureUserInfo(username); 
		
			$().SPServices({
				operation: 'UpdateListItems',
				async: 'false',
				listName: '{612F2856-20C1-4972-AD3D-EE4EE0231523}',
				updates: '<Batch OnError="Continue"> ' +
							'<Method ID="1" Cmd="New">' +
								'<Field Name="Title">"PowerPoint1"</Field>' +
								'<Field Name="username">' + username + '</Field>' +	//User
								'<Field Name="email">' + usrEmail + '</Field>' +
							'</Method>' +
						'</Batch>',		
				completefunc: function(xData, Status) {
					//alert("Status=" + Status + "XML=" + xData.responseXML.xml);	
				}
			});
		}
		function captureUserInfo(usrName){
		var userEmail;
			$().SPServices({
				operation:'GetUserInfo',
				userLoginName:usrName,
				completefunc: function (xData,Status){
					$(xData.responseXML).find('User').each(function(){
						userEmail =$(this).attr('Email');
						//alert("Status=" + Status + "XML=" + xData.responseXML.xml);	
					});
				}
			}); 
			
			return userEmail;
		}	
	});

 

Thanks for everything

Marcus

Coordinator
Feb 3, 2010 at 7:26 PM
Edited Feb 4, 2010 at 4:02 PM

Marcus:

Have you tried setting async: false in the GetUserInfo call?

M.

Feb 3, 2010 at 8:27 PM

Yes I have. Same Result. When the list is updated, the email column is always undefined by when the SubmitListInfo is complete is goes back to the alert I have in CaptureUserInfo and displays the correct info.

Coordinator
Feb 3, 2010 at 8:29 PM
Edited Feb 4, 2010 at 4:02 PM
OK. I'm on the road but will look at this as soon as I can.
M.
Feb 4, 2010 at 12:21 PM

I simplified this a bit unfortunately same result.

var userEmail;
	$(document).ready(function(){
		$('a[href$=PPT.aspx]').click(function (){		
		
		var username 	=$().SPServices.SPGetCurrentUser();	
			$().SPServices({
				operation:'GetUserInfo',
				userLoginName:username,
				async: 'false',
				completefunc: function (xData,Status){
					$(xData.responseXML).find('User').each(function(){
						userEmail =$(this).attr('Email');
						alert(userEmail);
						alert("Status=" + Status + "XML=" + xData.responseXML.xml);	
					});
				}
			}); 
			$().SPServices({
				operation: 'UpdateListItems',
				async: 'false',
				listName: '{612F2856-20C1-4972-AD3D-EE4EE0231523}',
				updates: '<Batch OnError="Continue"> ' +
							'<Method ID="1" Cmd="New">' +
								'<Field Name="Title">"PowerPoint1"</Field>' +
								'<Field Name="username">' + username + '</Field>' +	//User
								'<Field Name="email">' + userEmail + '</Field>' +
							'</Method>' +
						'</Batch>',		
				completefunc: function(xData, Status) {
					alert("Status=" + Status + "XML=" + xData.responseXML.xml);	
				}
			});
		return false;	
		});
	});

 

 

Feb 4, 2010 at 2:21 PM

I'm curious; which profile screen do you see when you use the following URL from your site (/_layouts/userdisp.aspx?Force=True)? You will see either the MySite profile screen or the internal site's Person Profile. I have seen in some cases that the internal site's Person Profile does not have the email address (or other fields) populated although that would not cause sporadic results.

Feb 4, 2010 at 2:46 PM

I was able to reproduce your issue using your code from above. I set async: false to your captureUserInfo function and had multiple successful results. Great suggestion Mark (as usual).

function captureUserInfo(usrName){
		    var userEmail;
			$().SPServices({
				operation:'GetUserInfo',
				async: false,
				userLoginName:usrName,
				completefunc: function (xData,Status){
					$(xData.responseXML).find('User').each(function(){
						userEmail =$(this).attr('Email');
						//alert("Status=" + Status + "XML=" + xData.responseXML.xml);	
					});
				}
			}); 
			
			return userEmail;
		}
Feb 4, 2010 at 3:54 PM

As I said in the original post, I knew I was going to feel stupid but I'll get over it.

Thank You Lawalker

and Thank You Mark

Coordinator
Feb 4, 2010 at 4:03 PM

Nice to see folks in the user community helping each other out.  ;+)

M.