Webhooks only when a new row is added to googlesheets

Hello makers,
I have created a scenario where I used webhooks on googlesheets to send email when a row added, but I get the trigger every time the googlesheets is updated not only when jut a row is added.
Any solution ? thanks

Welcome to the Make community!

Then you should not be using the webhooks module, instead use the Watch New Rows module.

samliew – request private consultation

Join the unofficial Make Discord server to chat with us!

2 Likes

Hello @variant,

You can use this acid module to and schedule it to resolve your issue. But by using this module you have to spend some extra operations because you need to schedule it. Or you can use custom google apps script to watch new rows using a trigger on edit and by checking onEdit event.

Thanks for sharing your query

2 Likes

Thank you @samliew and @AMIT_SOLANKI for your help.
I tried now the watch new row and scheduled it, but it take a lot of operations even with paid plan of make it will cost me a lot.
If I want to use google apps script how can I use it?

Hi @variant, I think you can still use your webhook but use a filter to target a specific word to filter to know if it’s a new row or an update ?

1 Like

Hey @variant ,

You can use this below code, what it will do is first it will check that if your current row count is greater than previously set property of script than only it will run below logic. You can implement a webhook in your scenario now and call it from here. and also pass data in payload. To perform further operation in make.


function onEdit(e) {
  var sheet = e.source.getActiveSheet();
  var currentNumRows = sheet.getLastRow();
  var scriptProperties = PropertiesService.getScriptProperties();
  var previousNumRows = parseInt(scriptProperties.getProperty('numRows'), 10) || 0;

  if (currentNumRows > previousNumRows) {
    var newRows = currentNumRows - previousNumRows;
    for (var i = 1; i <= newRows; i++) {
      var newRow = previousNumRows + i;
      var newRowValues = sheet.getRange(newRow, 1, 1, sheet.getLastColumn()).getValues()[0];
      Logger.log('New row added at row ' + newRow + ': ' + newRowValues);
    }
  }
  scriptProperties.setProperty('numRows', currentNumRows);
}

function initializeRowCount() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var currentNumRows = sheet.getLastRow();
  var scriptProperties = PropertiesService.getScriptProperties();
  scriptProperties.setProperty('numRows', currentNumRows);
}

3 Likes

Thank you All @samliew and @theophasbie and @AMIT_SOLANKI for your precious help, your answers helped me a lot.
:pray: :pray: :pray:

2 Likes

Hey there @variant :wave:

Great to hear that you received the needed assistance! :party_blob:

Would you mind marking the most helpful answer as a solution? This way we maintain our community organized and will be easy to look for solutions.

Thanks!

1 Like