I had a long search and until I found a working script to use the logged in user id. Finally I have found the following Javascript code, put it in XSL to be used in an XMl viewer web part:
<script language="javascript" defer="true">
<xsl:comment>
<![CDATA[
ExecuteOrDelayUntilScriptLoaded(init,'sp.js');
var currentUser;
function init(){
this.clientContext = new SP.ClientContext.get_current();
this.oWeb = clientContext.get_web();
currentUser = this.oWeb.get_currentUser();
this.clientContext.load(currentUser);
this.clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded), Function.createDelegate(this,this.onQueryFailed));
}
function onQuerySucceeded() {
}
function onQueryFailed(sender, args) {
alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
}
]]>
</xsl:comment>
</script>
I call the function like this:
<A class="bluelink" href = "javascript:void(0)" onclick="javascript:window.location='{$mailtolink}' + '%0D%0Auserid: ' + currentUser.get_loginName() + '%0D%0Aurl: ' + window.location; return false;">Request additional rights</A>
The mailtolink
variable represents a valid mailto:
link. The problem is, that in IE11 (also in IE8 compatibility mode), the mail body ends only with
userid: i:0
However in Chrome, I get all the details I need:
userid: i:0#.w|tdomain\testuser
url: https://myserver/testsite/default.aspx
I made the mail body shorter, to make sure it is not the lenght, but I got the same results. Can someone give me a hint how to make the script work in IE?
_spPageContextInfo.userLoginName
this variable provided by SharePoint and you can use that to get Login name.onQuerySucceeded
method is empty. That's where you getcurrentUser.get_loginName()
. If you could console this in browser developer tool. You might figure what's wrong there._spPageContextInfo.userLoginName
is only available since Sharepoint 2013, so that's not an option for me. TheonQuerySucceeded
method is empty, because I update thecurrentUser
object in the linecurrentUser = this.oWeb.get_currentUser();
If I put an alert inonQuerySucceeded
I get the popup with the correct userid.alert
inonQuerySucceeded
then your code is correct. Just need to update the flow. As far as my knowledge your execution is taking time and your HTML is already rendered by that time, So I would suggest you to have any DOM element and in youronQuerySucceeded
method, you should updateinnerHTML
of that element.