I want to select all items from a list where Title is equal to logInUser (which is current login user name).
In my code I have created : var logInUser = context1.get_web().get_currentUser();
But this doesn't work. Anyone can help? For my caml query ?? Thanks in advanced.
SP.SOD.executeFunc('sp.js','SP.ClientContext',readyFunction);
function readyFunction() {
getCurrentLoginUser();
getCurrentLoginUserDetails();
}
function getCurrentLoginUser() {
context = new SP.ClientContext.get_current();
web = context.get_web();
currentUser = web.get_currentUser();
currentUser.retrieve();
context.load(web);
context.executeQueryAsync(onQuerySucceeded,onQueryFailed);
}
function getCurrentLoginUserDetails() {
context1 = new SP.ClientContext.get_current();
oList = context1.get_web().get_lists().getByTitle('Employee Annual Leave Records');
var logInUser = context1.get_web().get_currentUser();
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(
'<View><Query><Where><Eq><FieldRef Name=\'Title\'/>' +
'<Value Type=\'Text\'>' + logInUser + '</Value></Eq></Where>' +
'</Query></View>'
);
collListItem = oList.getItems(camlQuery);
context1.load(collListItem);
context1.executeQueryAsync(onQuerySucceededD,onQueryFailedD);
}
function onQuerySucceeded(sender , args) {
var user = web.get_currentUser();
fd.field('Employee_x0020_Name').control().value(user.get_title());
}
function onQueryFailed(sender , args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
function onQuerySucceededD(sender , args) {
var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {
var oListItem = listItemEnumerator.get_current();
fd.field('Employee_x0020_Number').value(oListItem.get_item('Employee_x0020_Number'));
fd.field('Employed_x0020_Date').value(oListItem.get_item('Employed_x0020_Date'));
}
}
function onQueryFailedD(sender , args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}