Update current user information using SPServices and ECMAScript

Getting Details

var displayName = "";
function GetUser()
{
    displayName = $().SPServices.SPGetCurrentUser({
    fieldName: "Title"
    });    
    var ctx = new SP.ClientContext.get_current();
    this.currentUser = ctx.get_web().get_currentUser();
    ctx.load(this.currentUser);
    ctx.executeQueryAsync(Function.createDelegate(this, this.onSucceededGetUser),
    Function.createDelegate(this, this.onQueryFailed));
}
 
function onSucceededGetUser(sender, args)
{
    $("input[Title='Email']").val(this.currentUser.get_email());       
}
function onQueryFailed(sender, args)
{
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}  

Update Email ID

function UpdateUserEmail()
{          
    var ctx = new SP.ClientContext.get_current();
    this.currentUser = ctx.get_web().get_currentUser();
    var email = $("input[Title='Email']").val();
    this.currentUser.set_email(email);
    this.currentUser.update(); 
    ctx.executeQueryAsync(Function.createDelegate(this, this.onSucceededUpdateUserEmail),
    Function.createDelegate(this, this.onQueryFailed));
}
function onSucceededUpdateUserEmail(sender, args)
{
    alert("Sucess! " + this.currentUser.get_email());     
}



Comments

Popular posts from this blog

IRM and the Object Model

This content database has a schema version which is not supported in this farm

Activate and Deactivate Feature through PowerShell