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
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.
-
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– NotesArt2012-06-10 17:21:12 +00:00Commented 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– NotesArt2012-06-10 18:11:39 +00:00Commented Jun 10, 2012 at 18:11
-
1you are trying to use a property before calling ExecuteQuery();Falak Mahmood– Falak Mahmood2012-06-10 23:43:09 +00:00Commented 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.Marius Constantinescu– Marius Constantinescu2012-06-11 08:12:41 +00:00Commented Jun 11, 2012 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" >
-
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.Marius Constantinescu– Marius Constantinescu2012-06-11 20:28:55 +00:00Commented Jun 11, 2012 at 20:28