1

I need to create notifications for every user who didn't read a specific new on the site. To do this i need to see who user is logged in the site and then save this info into a list on Sharepoint. The problem is that i don't know where can i get this info on Sharepoint Online. I whould like to do this using javascript.

Someone can help me whith this. Thanks

2

Best and simple way to get current logged in user name is _spPageContextInfo.

_spPageContextInfo:

_spPageContextInfo is a global variable usually available on any SharePoint page. This variable stores basic information about current web and current user.

Below are the Some examples:

  1. To Get User Display Name:

    var currentUserName=_spPageContextInfo.userDisplayName;

  2. To Get User Login Name:

    var currentUserLoginName=_spPageContextInfo.userLoginName;

  3. To Get User Id:

    var userID=_spPageContextInfo.userId

  • Have you tried this? – Ganesh Sanap Nov 14 '18 at 14:10
  • Welcome. You can upvote and accept the answer. So that it will be closed. – Ganesh Sanap Feb 14 at 15:07
0

You can also use Rest API getting current user data:

 var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/currentuser";  
    $.ajax({  
        url: url,  
        headers: {  
            Accept: "application/json;odata=verbose"  
        },  
        async: false,  
        success: function (data) {  
            var items = data.d; // Data will have user object      
            console.log(items);
        },  
        eror: function (data) {  
            alert("An error occurred. Please try again.");  
        }  
    });  

This is the response data checked in Browser Console: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.