SharePoint 2013 Online Retrieve Current user details using SPServices

SharePoint 2013 Online Retrieve Current user details using SPServices

In this post, we will discuss how to retrieve current user details using SPServices in SharePoint Online or in SharePoint on-premise. We will retrieve username, email, first name etc using SPServices in SharePoint 2013/2016/Online.

If you are new to SPServices, read an article on Work with SPServices in SharePoint 2013/2016/Online.

SharePoint deveopment training course

You will be able to retrieve current users details like UserName, Email, FirstName, LastName ID etc using SPSercices in SharePoint 2013 Online. At the end find all the properties. You can retrieve single column values as well as you can also able to retrieve multiple column values. See 2nd example for this.

Below is the full code:
<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script>
<script type=”text/javascript” src=”//cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.min.js”></script>
<script type=”text/javascript” language=”javascript”>
$(document).ready(function() {
alert($().SPServices.SPGetCurrentSite());
alert($().SPServices.SPGetCurrentUser());
alert($().SPServices.SPGetCurrentUser(
{
fieldName:”ID”,
debug:false
}
));
alert($().SPServices.SPGetCurrentUser(
{
fieldName:”UserName”,
debug:false
}
));
alert($().SPServices.SPGetCurrentUser(
{
fieldName:”FirstName”,
debug:false
}
));
});
</script>

Get multiple column values:
<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script>
<script type=”text/javascript” src=”//cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.min.js”></script>
<script type=”text/javascript” language=”javascript”>
$(document).ready(function() {
var userdetails= $().SPServices.SPGetCurrentUser(
{
fieldNames:[“ID”,”EMail”,”UserName”,”FirstName”,”LastName”],
debug:false
}
);
alert(userdetails.ID);
alert(userdetails.EMail);
alert(userdetails.UserName);
alert(userdetails.FirstName);
alert(userdetails.LastName);
});
</script>

Below are the user properties which you can retrieve:

SharePoint 2013 Online Retrieve Current user details using SPServices
SharePoint 2013 Online Retrieve Current user details using SPServices

You may like following SPServices SharePoint 2013/2010 tutorials:

Hope this will be helpful to retrieve current user details like username, email id, first name, last name etc using SPServices in SharePoint 2013/2016 or SharePoint Online.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →