1

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.

4

Here's how you can get the current user login name in Javascript: 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>
| 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
1

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

| improve this answer | |
0

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
    });`
    
| improve this answer | |

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.