To anyone interested, I made this code and it is running very dynamically and instantly.
## Google Apps Script Code for Monitoring Spreadsheet Changes
This code monitors changes in a specific column of your Google Sheets and sends the modified row data to a Make webhook.
Step-by-Step Setup Guide:
- Use Google Sheets “Watch Changes” module
- Copy the provided webhook URL
- in google sheets go to
Extensions > Apps Script
- Paste the code above into the editor
- Make two changes in the code:
- Change
monitoredColumn
to the number of the column you want to monitor - Paste your Make webhook URL into the
webhookUrl
variable
- In the Apps Script editor, click on “Triggers” (clock icon) in the sidebar
- Configure the trigger for ‘onMake’ in event On Edit
- Save and finish.
How It Works
- The code monitors changes in the specified column
- When a change occurs, it:
- Identifies up to which column there are filled headers in row 1
- Captures all data from the modified row (from column A to the last column with header)
- Instantly sends this data to Make
Important Notes
- The code uses the first row as a reference to determine which columns to send
- If you add new columns with headers, the code will automatically include them
- The trigger must be manually configured for the code to work
- You can monitor any column by changing the number in
monitoredColumn
Code for script:
function onMake(e) {
var sheet = e.source.getActiveSheet();
var range = e.range;
// CONFIGURATION: Change the column number you want to monitor
// Example: 1 for column A, 2 for B, 3 for C... 32 for AF
var monitoredColumn = 32; // <-- CHANGE THIS NUMBER
// CONFIGURATION: Insert your Make (Integromat) webhook
var webhookUrl = "YOUR_WEBHOOK_HERE"; // <-- PASTE YOUR WEBHOOK HERE
// Check if the change was in the monitored column
if (range.getColumn() == monitoredColumn) {
var row = range.getRow();
var sheetName = sheet.getName();
var spreadsheet = e.source;
// Determine the last column with header in the first row
var headerRow = sheet.getRange("1:1").getValues()[0];
var lastValidColumn = 0;
for(var i = headerRow.length - 1; i >= 0; i--) {
if(headerRow[i] !== "") {
lastValidColumn = i + 1;
break;
}
}
// Get the values from the modified row
var rowValues = sheet.getRange(row, 1, 1, lastValidColumn).getValues()[0];
// Build the payload with the data
var payload = {
"spreadsheetId": spreadsheet.getId(),
"spreadsheetName": spreadsheet.getName(),
"sheetId": sheet.getSheetId(),
"sheetName": sheetName,
"rangeA1Notation": range.getA1Notation(),
"range": {
"columnEnd": range.getColumn(),
"columnStart": range.getColumn(),
"rowEnd": row,
"rowStart": row
},
"value": range.getValue(),
"user": {
"email": Session.getActiveUser().getEmail(),
"nickname": Session.getActiveUser().getEmail().split('@')[0]
},
"rowValues": [
rowValues.reduce((obj, value, index) => {
obj[index.toString()] = value;
return obj;
}, {})
]
};
// Request settings
var options = {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify([payload])
};
// Send data to webhook
UrlFetchApp.fetch(webhookUrl, options);
}
}
Questions
- Q: Why use row 1 as a reference? A: Row 1 typically contains headers and helps determine which columns contain relevant data.
- Q: Can I monitor multiple columns? A: Yes, you can modify the code to monitor multiple columns by adding more conditions to the if statement.
- Q: Does it work with protected sheets? A: Yes, but the user executing the script needs proper permissions.