1

I am trying to create custom NewForm.aspx. This form should auto populate current user login name display name and email details in the form when user load the NewForm.aspx.

Note : Without using jQuery and CSOM.

What is the query string parameter to get the current user info.

Is there is any way to get with the help of XSLT or else?

  • Have you tried setting the Default Value to [Me] ? – Mike Sep 20 '16 at 19:35
  • Yes [Me] working,, Similarly is there any way to get current user display name, Email and other attribute values? – Thirusanguraja Venkatesan Sep 21 '16 at 7:34
  • You should be able to choose one of those in the people and group column: msdnshared.blob.core.windows.net/media/MSDNBlogsFS/… To get more than one, maybe you should make multiple people and group columns one for each attribute. – Mike Sep 21 '16 at 13:09
  • @mike Do you have a way to auto-populate them with scripting? – Erin L Sep 21 '16 at 15:48
  • Are you talking scripting like Powershell or javascript? – Mike Sep 21 '16 at 23:25
2

You can use CSOM or SPServices to get the current user.

To use SPServices, you need to include the JQuery and the SPServices scripts.

var thisUsersValues = $().SPServices.SPGetCurrentUser({
    fieldNames: ["Title", "Email"],
    debug: false
});
  • There is any way without using CSOM. Using SPD custom? – Thirusanguraja Venkatesan Sep 20 '16 at 17:45
  • 1
    There's no method to get the current user in Designer. Though the script I gave you I would write in Designer. You can work around this by using a workflow to set a field to the Created By field, but it won't show in NewForm.aspx. – Erin L Sep 20 '16 at 18:14
  • 1
    I didn't see your "no jquery." CSOM doesn't use JQuery, but I don't have the code for that. – Erin L Sep 20 '16 at 18:24
  • Question updated – Thirusanguraja Venkatesan Sep 21 '16 at 7:36
0

If no code is important to you, you could have multiple "People and Group" columns that all default to the value of [Me]. Then you have one attribute per column that you want to show from that user. One shows Email, another shows Username, another shows Display Name. enter image description here

  • Apologies if i am not sure. I could not found Default value for People and Group column type. Can you please advise me? – Thirusanguraja Venkatesan Sep 22 '16 at 5:04
-1

I got solution for my question from Getting the Current User in SharePoint XSLT

SharePoint offers a couple of ways by which we can obtain the current user for use in a XSLT web part like DataFormWebPart or XsltListViewWebPart. All involve first setting parameters through the ParameterBindings property:

<ParameterBindings>
<ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
<ParameterBinding Name="LogonUser_" Location="WPVariable(_LogonUser_)"/>
<ParameterBinding Name="LogonUser" Location="ServerVariable(LOGON_USER)"/>
<ParameterBinding Name="AuthUser" Location="ServerVariable(AUTH_USER)"/>
<ParameterBinding Name="RemoteUser" Location="ServerVariable(REMOTE_USER)"/>
</ParameterBindings>
<Xsl>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl asp" xmlns:asp="System.Web.UI.WebControls" xmlns:ddwrt2="urn:frontpage:internal" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
<xsl:output method="html" />
<xsl:param name="UserID"/>
<xsl:param name="LogonUser_"/>
<xsl:param name="LogonUser"/>
<xsl:param name="AuthUser"/>
<xsl:param name="RemoteUser"/>
<xsl:template match="/">
UserID: <xsl:value-of select="$UserID"/><br/>
ID: <xsl:value-of select="ddwrt:UserLookup($UserID, 'ID')" /><br/>
EMail: <xsl:value-of select="ddwrt:UserLookup($UserID, 'EMail')" /><br/>
Login: <xsl:value-of select="ddwrt:UserLookup($UserID, 'Login')" /><br/>
LogonUser_: <xsl:value-of select="$LogonUser_"/><br/>
AuthUser: <xsl:value-of select="$AuthUser"/><br/>
RemoteUser: <xsl:value-of select="$RemoteUser"/><br/>
</xsl:template>
</xsl:stylesheet>
</Xsl>

Here we see different kinds of parameters:

  • CAMLVariable: built in variables UserID and Today;
  • WPVariable: returns one of the predefined values for WPID (web part client id), WPQ (web part unique id in page), WPR (web part resources folder full URL), WPSRR (web part resources folder relative URL), LogonUser (server variable LOGON_USER), WebLocaleId (current site locale, as in CultureInfo.LCID);
  • ServerVariable: returns one of the HTTP or IIS server- defined variables.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • Please don’t add just a link as answer to a question. If the link breaks, the answer you provided will not be useful for future visitors. Provide an answer of your own and use the link as reference. If needed, you can block quote the content from your link. More information is found in our help center, especially How do I write a good answer – Benny Skogberg Sep 21 '16 at 12:43
  • clever solution! – Mike Sep 21 '16 at 23:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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