I am tryting to create module pattern with ExecuteQueryAsync like this:
UsersMngt = (function () {
getUserIdByEmail = function(email){
var clientContext = new SP.ClientContext.get_current();
var web = clientContext.get_web();
var user = web.get_siteUsers().getByEmail(email);
clientContext.load(user);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
clientContext.executeQueryAsync(alert('yes'),alert('no'));
}; //getUserIdByEmail
return{
GetUserIdByEmail:getUserIdByEmail,
};
})();
and then I want to call it like:
UsersMngt.GetUserIdByEmail('[email protected]')
but, everytime I call it, with or without success, it always gives me both "yes" and "no" (success and failure). It also retrieves data I need in case of succces.
How can I include functions directly in "executeQueryAsync" without creating actually delegates somewhere else? I would like everything to be kept within the same code structure.
So far, it only works with delegates.
Thank you for ideas and help