我想从Title等于logInUser(这是当前登录用户名)的项目中选择all。
在我创建的代码中:var logInUser = context1.get_web().get_currentUser();
但这不起作用。
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());
}