Get logged in user using ECMA Script
function getWebUserData() {
$.blockUI();
// debugger;
web = context.get_web();
currentUser = web.get_currentUser();
currentUser.retrieve();
context.load(web);
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
}
function onSuccessMethod(sender, args) {
userObject = web.get_currentUser();
loggginname = userObject.get_loginName();
loggginname = loggginname.split("\\")[1];
currentUrl = window.location.origin;
currentUrl = currentUrl + "/";
var clientContext = new SP.ClientContext(currentUrl);
empBasicInfoLst = clientContext.get_web().get_lists().getByTitle("EmpBasicInfo");
spCamlQueryObj = new SP.CamlQuery();
spQueryGetUserInfo = "<View><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + loggginname + "</Value></Eq></Where></Query></View>";
spCamlQueryObj.set_viewXml(spQueryGetUserInfo);
empBasicInofColl = empBasicInfoLst.getItems(spCamlQueryObj)
clientContext.load(empBasicInofColl);
clientContext.executeQueryAsync(retrieveEmpBasicInfoListItemsSuccess, retrieveEmpBasicInfoListItemsFail);
}
$.blockUI();
// debugger;
web = context.get_web();
currentUser = web.get_currentUser();
currentUser.retrieve();
context.load(web);
context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
}
function onSuccessMethod(sender, args) {
userObject = web.get_currentUser();
loggginname = userObject.get_loginName();
loggginname = loggginname.split("\\")[1];
currentUrl = window.location.origin;
currentUrl = currentUrl + "/";
var clientContext = new SP.ClientContext(currentUrl);
empBasicInfoLst = clientContext.get_web().get_lists().getByTitle("EmpBasicInfo");
spCamlQueryObj = new SP.CamlQuery();
spQueryGetUserInfo = "<View><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + loggginname + "</Value></Eq></Where></Query></View>";
spCamlQueryObj.set_viewXml(spQueryGetUserInfo);
empBasicInofColl = empBasicInfoLst.getItems(spCamlQueryObj)
clientContext.load(empBasicInofColl);
clientContext.executeQueryAsync(retrieveEmpBasicInfoListItemsSuccess, retrieveEmpBasicInfoListItemsFail);
}
Comments