Get Current Logged in user using CSOM
Below is the sample code, need to copy paste in Content Editor webpart – HTML and it will help you fetch current logged in user details.
One needs to have basic knowledge of how to use Content Editor Webpart.
//Code Starts
<script src="https://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.6.2/jquery.SPServices-0.6.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
var currentUser = "";
$(document).ready(function() {
alert("Document ready");
AddItem();
});
function AddItem()
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
user = context.get_web().get_currentUser();
context.load(this.user);
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),
Function.createDelegate(this, this.onFailureMethod));
}
function onSuccessMethod(sender, args) {
currentUser = this.user.get_title();
var isSiteAdmin = user.get_isSiteAdmin();
alert(' Name:' + this.user.get_title() + '\n Login:' + this.user.get_loginName());
var tbl = $(this).closest('table');
{
var myTr = [];
$('.ms-listviewtable tr').each(function () {
var IsCurrentUser = false;
$(this).find('td').each(function () {
if($(this).text() == currentUser && !IsCurrentUser)
IsCurrentUser = true;
});
if(!IsCurrentUser)
$(this).attr( "disabled", "disabled");
});
}
}
function onFaiureMethod(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script> 
//Code ends.
Modern Workplace Architect Lead | Office 365 | SharePoint | Power Platform | SQL | Angular | MVC | Core
7 年Sir Think, title is wrong this is not rest api
JFDI Consulting
7 年Nope. No, no, no, no, no. https://www.youtube.com/watch?v=WrjwaqZfjIY a) This is CSOM. b) This is not REST. c) SPServices - why? Please see: https://msdn.microsoft.com/en-us/library/office/dn531432.aspx#bk_User https://www.enjoysharepoint.com/Articles/Details/get-current-logged-in-user-and-display-name-using-sharepoint-20688.aspx https://www.enjoysharepoint.com/Articles/Details/sharepoint-2013-get-current-login-user-profile-properties-through-rest-21127.aspx