function append()
{
Library.called_by_button();
}
function called_by_button(data_to_be_sent){
var date = new Date();
var dt = date.getFullYear() + '/' + date.getMonth() + 1 + '/' + date.getDate() + '-' + date.getHours()+ ':' + date.getMinutes()+ ':' + date.getSeconds();
var ss1 = SpreadsheetApp.getActive();
var id = ss1.getRange("B1").getValue();
var info = ss1.getRange("B4").getValue();
var data = {
'date': dt,
'a1': id,
'a2': info
};
var options = {
'method' : 'post',
'payload' : data,
muteHttpExceptions: true
};
// This is probably the best way to use UrlFetchApp() and handle errors.
var url = 'https://script.google.com/a/***/exec';
try {
var response = UrlFetchApp.fetch(url, options); // Post the data (make the HTTP Request)
var responseCode = response.getResponseCode();
if (responseCode === 200) { // 200 = SUCCESS
Logger.log("url_fetch() response code %s ", responseCode);
return response;
} else {
Logger.log(Utilities.formatString("url_fetch() Request failed for: %s, Expected 200, got %d",url,responseCode ));
return false;
//
}
}// end Try
catch (err) {
Logger.log(Utilities.formatString("url_fetch() Request failed (underlying network error). %s, response code: %s",err, responseCode));
return false;
}
}
function doPost(e){
var ss = SpreadsheetApp.getActive();
var ws = ss.getSheets()[0];
ws.appendRow([e.parameter.date, e.parameter.a1, e.parameter.a2]);
}
var spreadsheet = SpreadsheetApp.getActive();
var TEST = spreadsheet.getRange("B4").getValue();
var TWO = spreadsheet.getRange("B5").getValue();
var THREE = spreadsheet.getRange("B6").getValue();
var FOUR = spreadsheet.getRange("B7").getValue();
var FIVE = spreadsheet.getRange("B8").getValue();
function myFunction() {
var data = "[new Date(), TEST, TWO, FIVE, FOUR, THREE ];"
UrlFetchApp.fetch('https://script.google.com/a/***/exec', {payload: data});
};
var SHEET_ID = '***';
function doPost(e){
SpreadsheetApp.openById(SHEET_ID).getSheets()[0].appendRow(e.postData);
}