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.userLoginNamethis variable provided by SharePoint and you can use that to get Login name. – Pradip R. Jul 06 '17 at 09:57onQuerySucceededmethod 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. – Pradip R. Jul 06 '17 at 09:59_spPageContextInfo.userLoginNameis only available since Sharepoint 2013, so that's not an option for me. TheonQuerySucceededmethod is empty, because I update thecurrentUserobject in the linecurrentUser = this.oWeb.get_currentUser();If I put an alert inonQuerySucceededI get the popup with the correct userid. – vilmarci Jul 06 '17 at 10:11alertinonQuerySucceededthen 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 youronQuerySucceededmethod, you should updateinnerHTMLof that element. – Pradip R. Jul 06 '17 at 10:14