SharePoint Current Username – Add Username to Page

As an expansion to my reference to using SPServices to grab the current username in SharePoint, here is a simple Javascript example of using the GetCurrentUser function.

The following function obtains the current user name from SPServices and put’s it into a variable called “thisUser”. It then executes a text replace on the anchor text of the hyperlink, adding the username to the end.

Add the references to Jquery and SPServices in the section of your masterpage:

<script language="javascript" type="text/javascript" src="/jQuery%20Libraries/jquery-1.6.1.min.js"></script>
<script language="javascript" type="text/javascript" src="/jQuery%20Libraries/jquery.SPServices-0.6.2.min.js"></script>

Add the following in the section of your masterpage, or in a Content Editor Web Part:

<script language=”Javascript”>
function getUserName()
var thisUser = $().SPServices.SPGetCurrentUser({
	fieldName: "Name",
	debug: false
document.getElementById('myAnchor').href=”” + getUserName() + "/";
document.getElementById('myAnchor').innerHTML=”” + getUserName() + "/";

<a id="myAnchor" href=""></a>

The resulting output HTML for that anchor link would become (if logged in as JoeBlow):

<a id="myAnchor" href=""></a>

Leave a Reply

I've been low-key stressed about how to view the many email inboxes I have in Outlook in one view without having to scroll and hunt for new messages.

The 'macro' method in this video works great.

View Multiple Inboxes at Once in Outlook 365 via @YouTube

We help Department of Defense clients realize benefits such as faster decision making, total traceability, and automated updates by identifying targeted goals and putting an emphasis on a culture of adoption through buy-in by individual team members.

How to: Create a report quickly from a #SharePoint list or library in the #PowerBI service

Leverage Microsoft Project for the web with the Project Accelerator via @YouTube

Load More...