0

I have a Function named "ViewItem" that calls 2 more functions: "success" and "failed". When "success" is called it goes and check if a value exists and return true if the value exists or false if the value doesnt exist. Lastly I have a 4th function called "PresaveAction" what this function does is check if a value is "yes" or "no", if "no" it returns true and allows me to save and what I want to achieve is if the value is "yes" call the "success" function from before and depending if "success" returns true or false allow me to save. I keep going in circles any help will be greatly appreciated.

function ViewItem()
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('demoTrainingRoom2');
var query = SP.CamlQuery.createAllItemsQuery();
allItems = list.getItems(query);
context.load(allItems, 'Include(Title, EventDate, tiempo2)');

context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
}

function success() {
 
var currentTitle = SPUtility.GetSPFieldByInternalName('EventDate').GetValue(); 
for(var i = 0; i < this.allItems.get_count(); i++){
      var item = this.allItems.get_item(i);
      console.log(item.get_item('tiempo2') + ' - ' + currentTitle );
                           
                     if (currentTitle == item.get_item('time2')){
                     alert('There is an event with the same Start Date on DemoTrainingRoom2' + ' ' + item.get_item('time2') + ' - ' + currentTitle );
                      return true; // or item
          }
      }
      return false;
    }
    
function failed(sender, args) {
alert("failed. Message:" + args.get_message());
}


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; //allows me to save
    }
    

    else
{
   
 alert('Need to validate date');
 
 //this is were I need to called success

 }
   

}
kazzius
  • 9
  • 2
  • 8

0 Answers0