Don't save the record if the function returns false otherwise save the record

  • 0
  • 1
  • Question
  • Updated 1 year ago
  • Answered
  • (Edited)

I have a child function alertMSGS so the alertMSGS function checks the values in four variables and gives a alert message that they are not equal, so it will return false to the parent function which is DoSave() its a closure function , from my knowledge . So if the return is false i need to exit the save otherwise need to perform the save. !! See below . Many Thanks in advance

function alertMSGS(){  <br>   var currentWeekEarning = parseFloat( $("#_fid_19").val() );   
 var totalYearEarning= parseFloat( $("label[for=_fid_39]").next("div").text().replace('$', '').replace(',', '') );      
var currentLoss = parseFloat($("#_fid_20").val());
      var totalYearLoss= parseFloat($("label[for=_fid_38]").next("div").text().replace('$', '').replace(',', '') )
      if( (currentWeekEarning != totalYearEarning) ){
        alert("currentWeekEarning  Not Equal to totalYearEarning");
        return false;

      }
      if ( currentLoss != totalYearLoss) {
        alert(' currentLoss Not Equal to totalYearLoss');
        return false;
      }
    }


    DoSave = (function(fn){
      return function(){
      var resultofalertMSGS = alertMSGS();
      if (resultofalertMSGS === false) {
       // so if the function returns  false then  i need to exit from the (DoSave Function) and if it satisfies then i need to perform the (DoSave Function)
      }
        var result=fn.apply(fn, arguments);
        return result;
      };
})(DoSave);


I got the DoSave() function code from quickbase itself , so i hope i will get a reply on this. 
Photo of John Thomas

John Thomas

  • 1,062 Points 1k badge 2x thumb

Posted 1 year ago

  • 0
  • 1
Photo of John Thomas

John Thomas

  • 1,062 Points 1k badge 2x thumb
I got the solution. i hope this will help anyone 


DoSave = (function(fn){
      return function(){
      var resultofalertMSGS = alertMSGS();
      if (resultofalertMSGS === false) {
        return false;
       
}else{
        var result=fn.apply(fn, arguments);
        return result;
      }
}
})(DoSave);
(Edited)