Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to pass the current login user data from SharePoint 2010 to another web application. I am trying to use the javascript code to get the user and then pass it to the web application. I dont know where to start. My scenario is that I need to put a link on the SharePoint which would open a new form on a different web application and populate the user name value into it.

Any help would be appreciated.

Thanks in advance.

share|improve this question
add comment

3 Answers 3

up vote 4 down vote accepted

Here's how you can get the current user login name in Javascript: http://www.learningsharepoint.com/2011/05/18/get-current-users-loginname-ecmascript-sharepoint-2010/

<script type="text/javascript">
var context = null;
var web = null;
var currentUser = null;
ExecuteOrDelayUntilScriptLoaded(GetUserLoginName, "sp.js");
function GetUserLoginName() {
context = new SP.ClientContext.get_current();
web = context.get_web();
this._currentUser = web.get_currentUser();
context.load(this._currentUser);
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod),
Function.createDelegate(this, this.onFailureMethod));
}
function onSuccessMethod(sender, args) {
var today = new Date();
alert(' Name:' + this._currentUser.get_title() + '\n Login:' + this._currentUser.get_loginName());
}
function onFaiureMethod(sender, args) {
alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
share|improve this answer
    
Hi, Thanks for the solution. I had already tried this but this only gives me the name through the alert and provides a pop up. I need to copy the username and paste it into a form in another web application. I need to pass this username to different server. –  Thisisme.. Mar 8 '12 at 1:02
add comment

Use SPServices Jquery from CodePlex.

Do the necessary steps:

  1. Download the latest jquery.js from SPServices Jquery.

  2. Upload the minnified js file to the style library of your site.

  3. Add the script link <script type="text/javascript" src="Path of the JS file"> </script> to the master page.

  4. Add the following code

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

share|improve this answer
add comment

This code sometimes work well, sincerely I prefer use to SPServices.

with jquey:

var Username = $("#zz16_Menu").text();
alert(Username+" yname");

with only javascript:

var Username = document.getElementById("zz16_Menu").innerHTML ;
var end = Username.indexOf("<");
var nameOnly = Username.substring(8, end);
alert(nameOnly+" xname");

Best Regards

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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