-
-
Notifications
You must be signed in to change notification settings - Fork 204
Debugging tips
Derek Antrican edited this page Aug 24, 2019
·
7 revisions
Developing with Visual Studio Code (via clasp)
- Follow these steps to get clasp set up with Visual Studio code on your computer
- Create a new folder where you want the repo to be and
cd
to that folder - Make a copy of the script to your Google Drive.
- Clone the repo with
clasp clone YOUR_GAS_SCRIPT_ID
(or, if you don't know the ID you can just useclasp clone
and it will list your GAS scripts that you can choose from) - You should be set up!
(I have not yet figured out how to debug with Visual Studio Code yet, but this should be on the right track. Please feel free to let me know if you figure it out and I'll update this
Development workflow
If developing with VS Code and clasp, the development workflow would be like this:
clasp pull
- Do edits in VS Code
clasp push
- Test edits by running functions in Google Apps Script IDE online
- Use git chrome extension from GAS IDE to commit to this Github repository
My note above about debugging in VS Code would get rid of step 4 as you would be able to test edits in VS Code
A useful method to add is the following:
function createFreshCalendar(){
var cal = CalendarApp.getCalendarsByName(targetCalendarName)[0];
if (cal != null)
cal.deleteCalendar();
cal = CalendarApp.createCalendar(targetCalendarName);
cal.setColor('#c700ff');
cal.setSelected(true);
}
Then, as the very first line of main()
you can call the method. This will create a fresh calendar every time you run the main()
function.
You can add a string like this:
var sourceCalendarString =
"BEGIN:VCALENDAR\n"+
"PRODID;X-RICAL-TZSOURCE=TZINFO:-//com.denhaven2/NONSGML ri_cal gem//EN\n"+
"CALSCALE:GREGORIAN\n"+
"VERSION:2.0\n"+
"METHOD:PUBLISH\n"+
"BEGIN:VTIMEZONE\n"+
"TZID;X-RICAL-TZSOURCE=TZINFO:America/Chicago\n"+
"BEGIN:STANDARD\n"+
"DTSTART:20181104T020000\n"+
"RDATE:20181104T020000\n"+
"TZOFFSETFROM:-0500\n"+
"TZOFFSETTO:-0600\n"+
"TZNAME:CST\n"+
"END:STANDARD\n"+
"BEGIN:DAYLIGHT\n"+
"DTSTART:20190310T020000\n"+
"RDATE:20190310T020000\n"+
"TZOFFSETFROM:-0600\n"+
"TZOFFSETTO:-0500\n"+
"TZNAME:CDT\n"+
"END:DAYLIGHT\n"+
"END:VTIMEZONE\n"+
"BEGIN:VEVENT\n"+
"EXDATE;TZID=America/Chicago:20190103T183000\n"+
"EXDATE;TZID=America/Chicago:20190131T183000\n"+
"DTEND;TZID=America/Chicago;VALUE=DATE-TIME:20181129T203000\n"+
"DTSTART;TZID=America/Chicago;VALUE=DATE-TIME:20181115T183000\n"+
"DTSTAMP;VALUE=DATE-TIME:20190128T180311Z\n"+
"UID:c0412328-07fb-463c-81f0-0b97f0544219\n"+
"DESCRIPTION:Test description\n"+
"SUMMARY:Test title\n"+
"RRULE:FREQ=WEEKLY;INTERVAL=1;UNTIL=20190322T045959Z;BYDAY=TH\n"+
"LOCATION:Main Street Sports Center\n"+
"END:VEVENT\n"+
"END:VCALENDAR";
and change
var jcalData = ICAL.parse(response);
to
var jcalData = ICAL.parse(sourceCalendarString);