I want to get the return value true or false of res2 and use it in the last return. So it can works like the first validation on PreSaveAction the one validating demoField value.
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
}
}