Uncaught RangeError: Maximum call stack size exceeded at Object (native)

Anna OriasAnna Orias Member
edited July 2017 in Problems
We are suddenly getting this error on this code. The code was working fine and now is it throwing this error. 


skuid__JQueryJS:2 Uncaught RangeError: Maximum call stack size exceeded
    at Object (native)






var params = arguments[0],
    $ = skuid.$;
alert('Are you sure that you want to Enroll in Private Lessons?');console.log('start');
// get the last day to create bookings to from the MMA_Enrollment object
var enrollment_end_date =  skuid.model.getModel('MMA_Enrollment').data[0].Enrollment_End_Date__c;
console.log('end date for enrollment' + enrollment_end_date);

if (!enrollment_end_date){
    // if that field is blank, alert the user and exit the code
    window.alert("There is no end date for this enrollment. Please enter an enrollment end date.");
    return;
}

// get a javascript version of the last date
var last_date = skuid.time.parseSFDate(enrollment_end_date);
// open the bookings model so we can add records to it
var model = skuid.model.getModel('MMA_Private_Lesson_Enrollment_Booking');

// check and see that the bookings model is not empty... the user should have created the first booking record
if (model.data.length > 0 ) {
    // get the first record in bookings (record 0)
     row = skuid.model.getModel('MMA_Private_Lesson_Enrollment_Booking').data[0];
    // console.log(row);
     //console.log(row.Start_Date_And_Time__c);
     // get the value in the start date and time field
     var start_date_and_time = row.Start_Date_And_Time__c;
     // convert the salesforce value to a javascript date
     var start_date = skuid.time.parseSFDateTime(start_date_and_time);
     //console.log('start date as date ' + start_date);
     var end_date_and_time =  row.End_Date_And_Time__c;
     var end_date = skuid.time.parseSFDateTime(end_date_and_time);
     //console.log('start date ' + start_date_and_time + ' end date ' + end_date_and_time);
     var lesson_number = row.Lesson_Number__c;
     // use javascript date functions to extract the hour and minutes
     var start_hour = start_date.getHours();
     var start_minute = start_date.getMinutes();
     var end_hour = end_date.getHours();
     var end_minute = end_date.getMinutes();
     //console.log('hours and minutes ' + start_hour + " " + start_minute + " " + end_hour + " " + end_minute);
    // set the counter we're going to use as a safety valve
    var counter = 1;
    //console.log('before loop starts counter ' + counter + 'start date ' + start_date_and_time + ' enrollment end date ' + last_date);
    // now we start creating bookings... each time we advance the date... when the date passes the end date the loop will stop
    while (start_date <= last_date && counter < 100 ) {
       if(counter>1){
            var is_skip = Cal.is_skip_day(start_date).is_day;

            if (is_skip){
           
            }
            else{
                console.log ('in else block for start date' + start_date);
                // Create a new row in our table
                var newRow = model.createRow(),
                // create an empty object to store the field values in
                rowUpdates = {};
                // Put in default values from the fields in our current row
                if (row) {
                    $.each(row,function(fieldId,val) {
                        // Only allow fields that are Objects,
                        // or that are Createable
                        if (val !== null)  {
                            var modelField = model.getField(fieldId);
                            if ((typeof val === 'object') || (modelField && modelField.createable)) {
                                //console.log('fieldId:' + fieldId + ' ' + val);
                                // for each field we check for the fields we want to apply special treatment to
                                // if we find one we supply a new value for the "val" variable
                                var sf_date=0;
                                if (fieldId =='Start_Date_And_Time__c'){
                                val = skuid.time.getSFDateTime(start_date);
                                }
                   
                                if (fieldId =='End_Date_And_Time__c'){
                                    val = skuid.time.getSFDateTime(end_date);
                                }
                       
                                if (fieldId =='Lesson_Number__c'){
                                    //console.log('old lesson number' + lesson_number);
                                    if (is_day){
                                    val = 0;
                                    }
                                else{
                                    lesson_number = lesson_number + 1;
                                    val = lesson_number;
                                }
                                //console.log('new lesson number' + val);
                      
                                if (fieldId =='Booking_Price_actual__c'){
                       
                                    if (is_day){
                                    val = 0;
                                    }
                                }
                                //console.log('session tuition ' + val);
                       
                                //if (fieldId =='MMA_Group_Class_Session_Description__c'){
                       
                                //    if (is_day){
                                    val = 0;
                                //    }
                                //}
                      
                                //console.log('session tuition ' + val);
                                }
                            // whatever val ended up being... we add it to the rowUpdates object
                            rowUpdates[fieldId]=val;
                            }//if val is an object
                        }//if val not = no
                    });  // each
                } // if (row).. was the row created
                // now we use the rowUpdates object to update the whole row at once
                model.updateRow(newRow,rowUpdates);
                console.log('start date in loop ' + start_date);
                console.log( ' end date in loop ' + last_date );
                console.log( ' counter in loop ' + counter);
                console.log(start_date <= last_date);
            }//else for is skip
         }//counter greater than 1 
            // move the start date
                sf_date = start_date;
                sf_date.setDate(sf_date.getDate() + 7);
                val = skuid.time.getSFDateTime(sf_date);
                start_date = new Date(sf_date.getFullYear(),sf_date.getMonth(),sf_date.getDate(),start_hour,start_minute,0);
 
                sf_date = end_date;
                sf_date.setDate(sf_date.getDate() + 7);
                val = skuid.time.getSFDateTime(sf_date);
                end_date = new Date(sf_date.getFullYear(),sf_date.getMonth(),sf_date.getDate(),end_hour,end_minute,0);
          
        
            // increment the counter
            counter++;
            // reset the rowUpdates object to a new, and empty, object
            rowUpdates = {};
        } // while start date <= last date
    // now we save all our new bookings
    model.save({callback: function(result){ 
            // when salesforce finishes saving, then this function is called
                if (result.totalsuccess) { 
                    // if the save was successful, then we update the display of the model in our form
                    model.updateData();
                } else { 
                    console.log(result.insertResults); 
                    console.log(result.updateResults); 
                    console.log(result.deleteResults); 
                } // if result is totalsuccess
            } // the function
        }); // the callback
    }else{
         window.alert("The first lesson is not entered. Please enter the first lesson.");
    }




Here is the code for the Cal.is_skip

(function(skuid){
    var $ = skuid.$;
    if (typeof Cal==='undefined'){Cal = {}} 
    Cal.is_skip_day = function(date_to_test){
        //console.log(date_to_test);
        skip_day_model_data = skuid.model.getModel('MMA_Academic_Season_Skip_Day').data;
        number_of_skip_days = skip_day_model_data.length;
        //console.log('number of skip days ' + number_of_skip_days)
        date_to_test_string = Cal.convert_date(date_to_test);
        //console.log('date string to test' + date_to_test_string);
        is_day = false;
        skip_day_date = date_to_test_string;
        skip_day_name = "Private Lesson";
      
        for (i=0;i<number_of_skip_days;i++){
            skip_day_date = skip_day_model_data[i].Skip_Day_Date__c;
            //console.log('date to test ' + date_to_test_string + '= skip day date' + skip_day_date  );
            // console.log('date to test ' + date_to_test_string.toString() + '= skip day date' + skip_day_date.toString()  );
           skip_day_date = skip_day_date.toString();
            if (skip_day_date == date_to_test_string){
                //console.log ('========>is a skip day')
                is_day = true;
                skip_day_date =skip_day_model_data[i].Skip_Day_Date__c;
                skip_day_name =skip_day_model_data[i].Name;
                var result = {is_day:is_day,skip_day_date:skip_day_date,skip_day_name:skip_day_name};
                break;
            }
            
        }
        
         result = {is_day:is_day,skip_day_date:skip_day_date,skip_day_name:skip_day_name};
       // console.log(result);
        return result
    };
    
    Cal.convert_date = function(date_to_convert){
        var this_date = new Date(date_to_convert);
      
  var year = this_date.getFullYear();
  var month = this_date.getMonth() + 1;
   month = month < 10 ? '0'+month : month;
    var day = this_date.getDate();
   day = day < 10 ? '0'+day : day;
  
  var result = year + '-' + month + '-' + day;
  return result;

    };


})(skuid);

Comments

Sign In or Register to comment.