我想获得res2的返回值true或false,并在最后一次返回时使用它。因此它可以像PreSaveAction上的第一个验证一样验证demoField值。
function ViewItem(listTitle, Success, Error) {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle(listTitle);
var query = SP.CamlQuery.createAllItemsQuery();
var allItems = list.getItems(query);
context.load(allItems, 'Include(Title, EventDate, tiempo2)');
context.executeQueryAsync(function(){
var currentTitle = SPUtility.GetSPFieldByInternalName('EventDate').GetValue();
var res = "No";
for (var i = 0; i < allItems.get_count(); i++) {
var item = allItems.get_item(i);
console.log(item.get_item('tiempo2') + ' - ' + currentTitle );
if (currentTitle == item.get_item('tiempo2')){
res = "Si";
console.log('There is an event with the same Start Date on DemoTrainingRoom2'
+ ' ' + item.get_item('tiempo2') + ' - ' + currentTitle);
}
}
return Success(res);
},
Error
);
}
function PreSaveAction() {
var time = SPUtility.GetSPFieldByInternalName('EventDate').GetValue();
alert(time + " Current Start Time ");
if(SPUtility.GetSPField('demoField').GetValue() == "no") {
alert('No need for validation');
return true;
}
else if(SPUtility.GetSPField('demoField').GetValue() == "yes") {
var res2 = ViewItem('demoTrainingRoom2', function(res){
console.log('Result: ' + res);
if(res == "Si")
{
alert(res);
return false; //I want this or
}
else
{
alert(res);
return true; // This
}
},
function (sender, args) {
alert("failed. Message:" + args.get_message());
}
)
;
return res2; // Over here
}
}
&#13;