Skip to content

Instantly share code, notes, and snippets.

@ryanjonhealy
Created April 23, 2015 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanjonhealy/44a93ac73932a46252fc to your computer and use it in GitHub Desktop.
Save ryanjonhealy/44a93ac73932a46252fc to your computer and use it in GitHub Desktop.
function CustomExecuteFunction() {
var self = this;
self.context = new SP.ClientContext.get_current();
self.web = context.get_web();
self.currentUser = web.get_currentUser();
context.load(self.currentUser);
self.asyncSuccess = function(sender, args) {
var user = this.currentUser;
console.log('asyncSuccess', user);
loc = window.location.href;
check = loc.indexOf('CurrentUser');
if(check <0)
{
// if not the redirect with appended query string
window.location= loc + "?CurrentUser=" + user.get_title();
}
};
self.asyncFailure = function(sender, args) {
alert('Request failed. \nError: ' + args.get_message() + '\nStackTrace: ' + args.get_stackTrace());
};
// actually fires off the AJAX request
// more info: http://msdn.microsoft.com/en-us/library/dn168907.aspx
context.executeQueryAsync(
Function.createDelegate(self,self.asyncSuccess),
Function.createDelegate(self,self.asyncSuccess)
);
}
ExecuteOrDelayUntilScriptLoaded(CustomExecuteFunction,'sp.js');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment