Reputation: 2476
I've been asked to look at a website. I have little html background but would like to access some SharePoint information with javascript. I opened up my console and tried:
var value = SP.Web.get_currentUser();
, but it was an Uncaught TypeError.
_spPageContextInfo.userId;
on the otherhand, works.
Any thoughts on how to get the first one working?
Thank you
Upvotes: 0
Views: 447
Reputation: 1962
You cannot access the Web.get_currentUser()
without loading first.
You can get currentUser()
like:
var clientContext = new SP.ClientContext.get_current();
var oWeb = clientContext.get_web();
currentUser = oWeb.get_currentUser();
clientContext.load(currentUser); // prepare your query
clientContext.executeQueryAsync( // submit your query to the server
function(){ // on success
// var loginName = currentUser.get_loginName();
// var userId = currentUser.get_id();
// var userTitle = currentUser.get_title();
// var userEmail = currentUser.get_email();
}, function(){ // on error
alert('Error: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
});
Read more on here: https://sharepoint.stackexchange.com/a/128137
Upvotes: 1