简体   繁体   中英

Modify Existing Google Calendar Events

Below is the script I created to modify existing calendar events. My goal is to change the description to have it change from a Register button to Registration Closed. The script works in that it will add guests, however it will not update the description to the new description when the max number of registrants has been exceeded. I did not include the part of the script that details the calProperties.

function modifyEvents() {
    var ss = SpreadsheetApp.getActive();
    var sheet = ss.getSheetByName("Events");
    var sheetR = ss.getSheetByName("Registration");
    var headerRows = 1;
    var dataRange = sheet.getDataRange();
    var data = dataRange.getValues();
    for (var i = 1; i in data; ++i) {
        if (i << headerRows) {
            var row = data[i];
            var room = row[5];
            var description = row[6];
            var agegroup = row[7];
            var registration = row[8];
            var max = row[10];
            var calname = row[14];
            var eventId = row[15];
            var registrants = row[17];
            var calendarName = sheet.getRange(headerRows + i, 15).getValue();
            var calendarId = calProperties.getProperty(calendarName);
            var cal = CalendarApp.getCalendarById(calendarId);
            var id = sheet.getRange(headerRows + i, 16).getValue();
            var event = cal.getEventSeriesById(id);
            var email = sheetR.getRange(headerRows + i, 8).getValue();
            row[10] = sheet.getRange(headerRows + i, 11).getValue();
            row[17] = sheet.getRange(headerRows + i, 18).getValue();
                if (registration === 'Y' && registrants >> max) {//7.1 line 25
                    var description1 = (description + '\n' + '\n' + room + '\n' + '\nEvent Type: ' + calname + '\n' + '\nAge Group: ' + agegroup)
                    var descriptionHTML = '\n <div id="registration_button" ><a style="text-align:right;color:white!important;text-decoration:bold;background-color:rgb(209,72,54);background-image:-webkit-linear-gradient(top,rgb(221,75,57),rgb(209,72,54));color:#ffffff;border:1px solid rgba(0,0,0,0);border-radius:2px;display:inline-block;font-size:12px;font-weight:bold;height:27px;line-height:27px;padding:0px 20px 0px 20px;text-align:center;text-transform:uppercase;white-space:nowrap;text-decoration:none;color:white" target="_blank">Registration Closed</a>';
                    var descriptionRegistration = (description1 + '\n' + '\n' + descriptionHTML);
                    event.setDescription(descriptionRegistration);
                }
        }
    }
}

replace (i << headerRows)

with (i < headerRows)

and replace registration === 'Y' && registrants >> max

with registration === 'Y' && registrants > max

there is a difference between > and >= which are greater than , greater than or equal to and :

>> << which are bitwise operands left and right which you clearly did not want

<< left shift Shifts a in binary representation b (< 32) bits to the left, shifting in zeroes from the right.

>> Sign-propagating right shift Shifts a in binary representation b (< 32) bits to the right, discarding bits shifted off.

What you want are > Greater Than "The greater than operator returns true if the left operand is greater than the right operand."

or

< Less Than "The less than operator returns true if the left operand is less than the right operand."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM