Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to display the name of the user that is currently logged in SharePoint 2010 on the form of my Custom List. Please help. Thanks in advance for your help.

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Not sure how did you customized your form, but if by "NO-CODE" you only consider compiled, that one way would be to use the ECMA Javascript in a Content Editor Web Part (CEWP) which could add to the display form in addition to existing List View Web Part. YOu could create a simple JS file to upload in a Document Library (or any library for that matter where you store scripts) to which you need to add the following script (between tag):

var currentcontext = new SP.ClientContext.get_current();
var currentweb = currentcontext.get_web();
currentcontext.load(currentweb);
var currentuser = currentweb.get_currentUser();
currentuser.retrieve();
currentcontext.load(currentweb);
var loginName = currentuser.get_loginName();

(Full example available here http://www.learningsharepoint.com/2011/05/18/get-current-users-loginname-ecmascript-sharepoint-2010/) Depending on where exactly you want to do this, you could add an HTML element to the page and then using getElementById (of jQUery selectors - if you are already referencing it) to set its content to the return value.

share|improve this answer
    
Thanks a lot..but I am very new to SP..could you please explain it a bit..like step wise I should do it..Thanks again. –  NotesArt Jun 10 '12 at 17:21
    
I have tried it below way.. <asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server"> <script type="text/javascript"> function PreSaveAction() { var currentcontext = new SP.ClientContext.get_current(); var currentweb = currentcontext.get_web(); currentcontext.load(currentweb); var currentuser = currentweb.get_currentUser(); currentuser.retrieve(); currentcontext.load(currentweb); var loginName = currentuser.get_loginName(); alert(loginName) return false } </script> </asp:Content> But getting error that the property or field has not been initialized at before the alert. –  NotesArt Jun 10 '12 at 18:11
1  
you are trying to use a property before calling ExecuteQuery(); –  Falak Mahmood Jun 10 '12 at 23:43
    
I've updated my response with a link to an article showing a full execution example to get you started. –  C. Marius - MVP Jun 11 '12 at 8:12

You can use below control as well :

<wssuc:Welcome id="IdWelcome1" runat="server" EnableViewState="false"  >
            </wssuc:Welcome>

If you want to have it in xsl of list form, you may need to register before:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wssuc="Microsoft.SharePoint.WebControls" >
share|improve this answer
    
Amit: correct me if I'm wrong, but that actually that shows the whole User menu as shown on Top-Right in the OOTB v4.master, not simply the user name. –  C. Marius - MVP Jun 11 '12 at 20:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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