0

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.

2 Answers 2

2

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.

4
  • 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, 2012 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, 2012 at 18:11
  • 1
    you are trying to use a property before calling ExecuteQuery(); Jun 10, 2012 at 23:43
  • I've updated my response with a link to an article showing a full execution example to get you started. Jun 11, 2012 at 8:12
0

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" >
1
  • 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. Jun 11, 2012 at 20:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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