Does SharePoint get the current user account name?

Does SharePoint 2010 save the current user account somewhere in a globally accessible JS object?

Every solution I can find involves some modification to the ajax web service call, and this seems like an extremely difficult solution to access what should be trivial information.

I can easily access:

  • Get current user id from __spUserId
  • Get current username by clearing html feeds (for example: $('#zz17_Menu').text() )

But none of them is the name of the account.

Things I would prefer:

  • Get current user information with a SOAP call GetUserProfileByName
  • Get current user information by making an Ajax call to .. / _ layouts / userdisp.aspx
+6
source share
2 answers

For anyone who stumbles about it, a year later I realized how.

Register SPSWC on the main page (if you are using Randy Drisgill starter> it will already be there).

 <%@ Register Tagprefix="SPSWC" Namespace="Microsoft.SharePoint.Portal.WebControls" Assembly="Microsoft.SharePoint.Portal, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 

Then, before you want to access the property (for example: UserName), insert the data

 <SPSWC:ProfilePropertyLoader runat="server"/> 

Then, to access one of the properties, I would recommend using TitleMode to insert it into the <script> element.

 <script> var username = '<SPSWC:ProfilePropertyValue PropertyName="UserName" TitleMode="true" runat="server"/>'; </script> 

Now we use it, as shown in this PasteBin demo , to populate the global object with several properties, such as first name, last name, username, profile picture, status.

+5
source

You really need to make a web service call to make it reliable. Fortunately, SPServices makes it quick and painless for this.

http://spservices.codeplex.com/wikipage?title= $% 28% 29.SPServices.SPGetCurrentUser

 $().SPServices.SPGetCurrentUser({ fieldName: "Name", debug: false }); 
+1
source

Source: https://habr.com/ru/post/918586/


All Articles