Forum Discussion
Get Current User Details SharePoint Online
DCady Can you tell us which script editor web part are you using (any link to web part sample)?
I am using this Script Editor web part and I can get the user details using _spPageContextInfo variable (no need of JSOM/REST API call). For example, below code will return the title/display name of user:
_spPageContextInfo.userDisplayName
Similarly you can get user ID, Email & login name as mentioned in this post: Get user logged on sharepoint online .
Here is working example:
<p id="pWelcomeMsg"></p>
<script type="text/javascript">
document.getElementById("pWelcomeMsg").innerHTML = "Hey " + _spPageContextInfo.userDisplayName + ", welcome to our site";
</script>
Output:
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
Thanks for reaching out! I am currently utilizing that same script editor web part, that you have posted below. I am not exactly sure why it's not rendering the code. I have used the script editor to render other JS and HTML code but when it comes to obtaining user information, it will not render on my modern SharePoint page. I have attempted to utilize your example below with no luck. Also, I am an admin with full access.
- ganeshsanapMay 08, 2024MVP
DCady You have to enable the access to classic _spPageContextInfo from web part settings like:
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.