Получение ошибки после отправки пунктов повестки дня из листов Google в календарь Google - PullRequest
0 голосов
/ 10 февраля 2020

У меня следующая проблема, я хочу сделать новые пункты повестки дня из листов Google, используя скрипт, он работает, пока я не достиг предела?!. (сегодня я заработал 350, прежде чем возникла проблема.)

Я получаю следующее сообщение; «Исключение: Вы создали или удалили слишком много календарей или событий календаря за короткое время. Повторите попытку позже». Если я подожду несколько часов, я могу сделать еще несколько. Тогда ошибка возвращается.

Замедление работы скрипта не работает. (Utilities.sleep (300);) Код ниже,

function UpdateAgenda() {
  var spreadsheet = SpreadsheetApp.getActiveSheet();
  var Range = "B8";
  var activeDay =   spreadsheet.getRange(Range).getValue(); //ActiveSheet
  var Range = "E7";
  var DriverMorning =   spreadsheet.getRange(Range).getValue();  
  var Range = "F7";
  var DriverAfternoon =   spreadsheet.getRange(Range).getValue(); 
  var Range = "E3";
  var SendAgendaMorning =   spreadsheet.getRange(Range).getValue(); 
  var Range = "F3";
  var SendAgendaAfternoon =   spreadsheet.getRange(Range).getValue(); 
  var Range = "H3";
  var SendAgendaEvening =   spreadsheet.getRange(Range).getValue(); 
   var Range = "E4";
  var SendMailMorning =   spreadsheet.getRange(Range).getValue(); 
  var Range = "F4";
  var SendMailAfternoon =   spreadsheet.getRange(Range).getValue(); 
  var Range = "H4";
  var SendMailEvening =   spreadsheet.getRange(Range).getValue(); 



  var NoDriver = "false";
  var NoDriverMorning = "false";
  var NoDriverAfternoon = "false";

  if (activeDay == "Maandag" || activeDay == "Dinsdag" || activeDay == "Woensdag" || activeDay == "Donderdag" || activeDay == "Vrijdag" || activeDay == "Zaterdag" || activeDay == "Zondag"){ //Check for weekday
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var  Name = "AgendaData"+activeDay+"Ochtend"
  var AgendaOchtend = ss.getSheetByName(Name); //Bijbehorende Agenda's Ochtend
    var  Name = "AgendaData"+activeDay+"Middag"
  var AgendaMiddag = ss.getSheetByName(Name); //Bijbehorende Agenda's Middag
    var  Name = "AgendaData"+activeDay+"Avond"
  var AgendaAvond = ss.getSheetByName(Name); //Bijbehorende Agenda's Avond

    //Check if the agenda is already send
      var Range = "A1";
  var AgendaSend =   spreadsheet.getRange(Range).getValue(); //ActiveSheet


    if (AgendaSend == "Agenda is verstuurd"){ 

    //Show warning is Agenda is already send


  var ui = SpreadsheetApp.getUi(); // Same variations.

  var UpdateAgendaOpnieuw = ui.alert(
     'De agenda is al eens verstuurd.',
     'Weet u het zeker dat u door wilt gaan, het risico bestaad op dubbele agenda Items?',
      ui.ButtonSet.YES_NO);

  // Process the user's response.
  if (UpdateAgendaOpnieuw == ui.Button.YES) {
     SpreadsheetApp.getActiveSheet().getRange("A1").setValue("");
    AgendaSend = "False";
    ui.alert('Ok, de agenda word geupdate');
  } else {
    // User clicked "No" or X in the title bar.
    ui.alert('Handeling afgebroken');
  }

    }

        //Check if the moring and afternoon driver is filled in
    if (DriverMorning == "Geen Dienst"){  
    var NoDriverMorning = "true";
   ui = SpreadsheetApp.getUi(); // Same variations.

  var NoDriverMorning = ui.alert(
     'Er is geen chaffeur in de ochtend dienst ingevuld.',
     'Wilt u desondanks toch de rit versturen?',
      ui.ButtonSet.YES_NO);

  // Process the user's response.
  if (NoDriverMorning == ui.Button.YES) {
     SpreadsheetApp.getActiveSheet().getRange("A1").setValue("");
    ui.alert('Ok, de ritten worden verzonden');
     var NoDriverMorning = "false";
  } else {
    // User clicked "No" or X in the title bar.
    ui.alert('Handeling afgebroken');
  }

    }


            //Check if the moring and afternoon driver is filled in
    if (DriverAfternoon == "Geen Dienst"){  
     var NoDriverAfternoon = "true";
   ui = SpreadsheetApp.getUi(); // Same variations.

  var DriverAfternoon = ui.alert(
     'Er is geen chaffeur in de middagdienst ingevuld.',
     'Wilt u desondanks toch de rit versturen?',
      ui.ButtonSet.YES_NO);

  // Process the user's response.
  if (DriverAfternoon == ui.Button.YES) {
     SpreadsheetApp.getActiveSheet().getRange("A1").setValue("");
    ui.alert('Ok, de ritten worden verzonden');
     var NoDriverAfternoon = "false";
  } else {
    // User clicked "No" or X in the title bar.
    ui.alert('Handeling afgebroken');
  }

    }


    //Check for driver
    if (NoDriverMorning == "false" && NoDriverAfternoon == "false" ) {






    if (AgendaSend != "Agenda is verstuurd"){
      // 


   /////////////////////////////////////////Ochtend/////////////////////////////////////////////   
  var data = "";
  var RangeOchtendClean =new Array();
  var offset = 0; 
  range = "A2:AB";
  var RangeOchtend = AgendaOchtend.getRange(range);
  var v1 = RangeOchtend.getValues();
  for(var i = 0; i < v1.length; i++)  {
      if (v1[i][7] === "Rit Gevonden") {
     RangeOchtendClean[offset] = v1[i];
        offset = offset +1; // move offset by one if there is data.
      }
  }
      if (RangeOchtendClean.length != 0){
    //Send the data to calender.
     for(var i = 0; i < RangeOchtendClean.length; i++)  {
       //if (i % 10 == 0) { Utilities.sleep(3000); }//Sleep to prefent tomuch data in time
      Utilities.sleep(300);
       var shift = RangeOchtendClean[i];
      var NaamKlant = shift[0];
      var StartTijd = shift[1];
      var StopTijd = shift[2];
      var Genodigden = shift[3];
      var Uitnodiging = shift[4];
      var Omschrijving = shift[5]; 
      var Locatie = shift[6]; 
      var Driver = shift[24];
      var calendarId =shift[25];

      var event = {
          'location': Locatie,
          'description': Omschrijving,
          'guests':Driver +',',
          'sendInvites': Uitnodiging,
}

      var eventCal = CalendarApp.getCalendarById(calendarId);
   if (Genodigden != "Geen Dienst"){
     if (SendAgendaMorning == "Ja"){
   eventCal.createEvent(NaamKlant, StartTijd, StopTijd, event) 
     }}} 
    var subject = RangeOchtendClean[0][22] + " Ochtend";
     for(var i = 0; i < RangeOchtendClean.length; i++)  {
      data = data + RangeOchtendClean[i][23];   
     }
     //   data = data + "Link naar Calender = " + RangeOchtendClean[(i - 1)][26] ; //Alles moet dan op public staan. Dus de gegevens van de mensen komen dan op straat. Dit staat alleen nog op Maandag ochtend goed. Op alle sheets nog aanpassen

    var emailAddress = Driver; // First column
    var message = data ; // Second column
   if (Genodigden != "Geen Dienst"){ 
     if (SendMailMorning == "Ja"){
  MailApp.sendEmail(emailAddress, subject, message);
     }}}


//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Ochtend\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\





    /////////////////////////////////////////Middag/////////////////////////////////////////////   
  var data = "";
  var RangeMiddagClean =new Array();
  var offset = 0; 
  range = "A2:AB";
  var RangeMiddag = AgendaMiddag.getRange(range);
  var v1 = RangeMiddag.getValues();
  for(var i = 0; i < v1.length; i++)  {
      if (v1[i][7] === "Rit Gevonden") {
     RangeMiddagClean[offset] = v1[i];
        offset = offset +1; // move offset by one if there is data.
      }
  }
      if (RangeMiddagClean.length != 0){
    //Send the data to calender.
     for(var i = 0; i < RangeMiddagClean.length; i++)  {
    //    if (i % 10 == 0) { Utilities.sleep(3000); }//Sleep to prefent tomuch data in time
     Utilities.sleep(300);
       var shift = RangeMiddagClean[i];
      var NaamKlant = shift[0];
      var StartTijd = shift[1];
      var StopTijd = shift[2];
      var Genodigden = shift[3];
      var Uitnodiging = shift[4];
      var Omschrijving = shift[5]; 
      var Locatie = shift[6]; 
      var Driver = shift[24];
      var calendarId =shift[25];

      var event = {
          'location': Locatie,
          'description': Omschrijving,
          'guests':Driver +',',
          'sendInvites': Uitnodiging,
}

      var eventCal = CalendarApp.getCalendarById(calendarId);
   if (Genodigden != "Geen Dienst"){
     if (SendAgendaAfternoon == "Ja"){
   eventCal.createEvent(NaamKlant, StartTijd, StopTijd, event) 
     }}} 
    var subject = RangeMiddagClean[0][22]+ " Middag";
     for(var i = 0; i < RangeMiddagClean.length; i++)  {
      data = data + RangeMiddagClean[i][23];   
     }
    var emailAddress = Driver; // First column
    var message = data; // Second column
   if (Genodigden != "Geen Dienst"){ 
     if (SendMailAfternoon == "Ja"){
  MailApp.sendEmail(emailAddress, subject, message);
     }}}
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Middag\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\





   /////////////////////////////////////////Avond/////////////////////////////////////////////   
   var data = "";
  var RangeAvondClean =new Array();
  var offset = 0; 
  range = "A2:AB";
  var RangeAvond = AgendaAvond.getRange(range);
  var v1 = RangeAvond.getValues();
  for(var i = 0; i < v1.length; i++)  {
      if (v1[i][7] === "Rit Gevonden") {
     RangeAvondClean[offset] = v1[i];
        offset = offset +1; // move offset by one if there is data.
      }
  }
      if (RangeAvondClean.length != 0){
    //Send the data to calender.
     for(var i = 0; i < RangeAvondClean.length; i++)  {
    //    if (i % 10 == 0) { Utilities.sleep(3000); }//Sleep to prefent tomuch data in time
   Utilities.sleep(300);
       var shift = RangeAvondClean[i];
      var NaamKlant = shift[0];
      var StartTijd = shift[1];
      var StopTijd = shift[2];
      var Genodigden = shift[3];
      var Uitnodiging = shift[4];
      var Omschrijving = shift[5]; 
      var Locatie = shift[6]; 
      var Driver = shift[24];
      var calendarId =shift[25];
      var event = {
          'location': Locatie,
          'description': Omschrijving,
          'guests':Driver +',',
          'sendInvites': Uitnodiging,
}

      var eventCal = CalendarApp.getCalendarById(calendarId);
   if (Genodigden != "Geen Dienst"){
     if (SendAgendaEvening == "Ja"){
   eventCal.createEvent(NaamKlant, StartTijd, StopTijd, event) 
     }}} 
    var subject = RangeAvondClean[0][22] + " Avond";
     for(var i = 0; i < RangeAvondClean.length; i++)  {
      data = data + RangeAvondClean[i][23];   
     }
    var emailAddress = Driver; // First column
    var message = data; // Second column
   if (Genodigden != "Geen Dienst"){ 
     if (SendMailEvening == "Ja"){
  MailApp.sendEmail(emailAddress, subject, message);
     }}}
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Avond\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\







    SpreadsheetApp.getActiveSheet().getRange("A1").setValue("Agenda is verstuurd");
  //  SpreadsheetApp.getActiveSheet().getRange("A1").setbackgroundcolor("#ff9900") // #ff9900 is default
    }
    }

    }



   }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...