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.
- GSkinner76May 07, 2024Copper Contributor
ganeshsanap Hi I just saw your solution/help for this member. I am trying to do something similar but in the new list item form ootb sp online. The window that appears on the side of the screen when they click new item i would like the CurrentUser details to be prepopulated is there a way of doing this without using powerapps as the com[pany i am doing this for has no powerapps licenses
- ganeshsanapMay 08, 2024MVP
GSkinner76 Unfortunately, you cannot add custom SPFx web part on the SharePoint default modern experience list forms.
For SharePoint online modern experience lists, you can either customize the list forms using SPFx or Power Apps.
Power Apps is easier and suitable for your requirements.
What Microsoft 365 (Office 365) license you are using in your company? If you are using E1, E3 or E5, you can use Power Apps for free as long as you use standard connectors.
Check:
- Find the right Microsoft 365 enterprise plan for your organization
- Power Platform - List of all Standard tier connectors
- Power Platform - List of all Premium tier connectors - These require additional Power Apps licenses
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.
- srinivaskandukuri1122Jul 21, 2024Copper Contributor
Hi ganeshsanap
I'm getting the below popup when i try to edit markup. Any idea why this is happening?
- DCadyJan 20, 2022Copper Contributor
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.