Foros‎ > ‎Sharepoint‎ > ‎

SharePoint 2013 get current user javascript

publicado a la‎(s)‎ 10 feb. 2015 6:40 por Ignacio Gonzalez
<script type="text/javascript" src="/_layouts/15/SP.js"></script>
<script type="text/javascript" src="/_layouts/15/SP.UserProfiles.js"></script>
<script type="text/javascript">

  var personProperties;

  SP.SOD.executeOrDelayUntilScriptLoaded(getCurrentUser, 'SP.UserProfiles.js');

  function getCurrentUser() {
    var clientContext = new SP.ClientContext.get_current();
    personProperties = new SP.UserProfiles.PeopleManager(clientContext).getMyProperties();
    clientContext.load(personProperties);
    clientContext.executeQueryAsync(gotAccount, requestFailed);
  }

  function gotAccount(sender, args) {
    alert("Display Name: "+ personProperties.get_displayName() + 
        ", Account Name: " + personProperties.get_accountName());
  }

  function requestFailed(sender, args) {
    alert('Cannot get user account information: ' + args.get_message());
  }

</script>
Comments