Reputation: 1058
I have a small script that saves data in Google Sheets. It looks at 3 cells and 'saves' them below. I have it set on a 'Project Trigger' every few hours and I also have a button. I would like to, in Column D, insert into the cell some text that indicates wether is was a trigger, or a manual button click ("Trigger"
,"Manual"
).
What I get at the moment is:
URL : follower_count : date
I would like:
URL : follower_count : date : trigger_status
Here is the code:
// function to save data
function saveData() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
var url = sheet.getRange('Sheet1!A3').getValue();
var follower_count = sheet.getRange('Sheet1!B3').getValue();
var date = sheet.getRange('Sheet1!C3').getValue();
sheet.appendRow([url, follower_count, date]);
}
Thank You.
Upvotes: 0
Views: 65
Reputation: 3344
From the Google Apps Script documentation:
Simple triggers and installable triggers let Apps Script run a function automatically if a certain event occurs. When a trigger fires, Apps Script passes the function an event object as an argument, typically called
e
.
Hence, when your function saveData
is called by the trigger it will be invoked with an argument. This way you will be able to tell if its "Manual" or "Trigger". I.e:
function saveData(e) {
var isTrigger = false;
if(e){
isTrigger = true;
}
...
}
Upvotes: 2