Get Current Logged In User Details In SharePoint Using SPServices JQuery Library
The $().SPServices JavaScript Add-on provide the function $().SPServices.SPGetCurrentUser, which will help to get the details of current logged-in user in the SharePoint site.
Get current logged-in user details using $().SPServices.SPGetCurrentUser:
var fieldDetails;
$(document).ready(function () {
fieldDetails = $().SPServices.SPGetCurrentUser({
fieldName: "Title",
debug: false
});
});
console.log(fieldDetails);
In the above code block, we are trying to get "Title" field details. Below is the listing of supported fields, which we can get against Logged-in user:
Get current logged-in user details using $().SPServices.SPGetCurrentUser, fields array:
$().SPServices.SPGetCurrentUser function also providing the facility to get more than one field details by passing the field details in array format:
var arrfieldDetails;
$(document).ready(function () {
arrfieldDetails = $().SPServices.SPGetCurrentUser({
fieldNames: ["Title", "Name", "EMail"],
debug: false
});
});
console.log(arrfieldDetails);
/*
Output:
Object
EMail:"amitkumar@amitkumarmca04.blogspot.com"
Name:"i:0#.f|membership|amitkumarmca04.blogspot.com" //--For SharePoint Online user
Title:"Amit Kumar"
*/