Skip to content

Instantly share code, notes, and snippets.

@basil2style
Created August 6, 2018 03:01
Show Gist options
  • Save basil2style/b72f03feddfb74f09b15673062ab7c64 to your computer and use it in GitHub Desktop.
Save basil2style/b72f03feddfb74f09b15673062ab7c64 to your computer and use it in GitHub Desktop.
Cron Scheduler in Google Script
#This is a cron job scheduler wrintten in Google App Script which insert Success and timestamp to Google Sheet if its
#successfully fetch the url otherwise it will return Error
var sheet = 'Sheet1';
function myFunction() {
var url = 'YOUR URL HERE';
var options = {
'method': 'get'
};
try {
var response = UrlFetchApp.fetch(url, options);
Logger.log(response);
var date= new Date();
addrow(date, 'Success');
} catch (error) {
addrow(date, 'Error');
}
}
function addrow(date, status) {
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheetFun = ss.getSheetByName(sheet);
// sheet.insertRowAfter(sheet.getActiveCell().getRow());
sheetFun.appendRow([date, status])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment