I want to create a button on a google sheets so that when you click it, that google sheet updates according to an scenario on make.com.
I want to avoid the minute by minute automated update for some scenarios that are consuming a lot of data and what I just need is a button than updates de google sheet whenever is needed.
Interesting to accomplish this you will need to create an AppScript function on your Google sheet.
Your function could looks like this:
function onEdit(e) {
var sheet = e.source.getActiveSheet();
var row = e.range.getRow();
// Specify the URL to send the POST request
var url = âhttps://YOURWENHOOKURLâ;
// Retrieve the data from the updated row
var rowData = sheet.getRange(row, 1, 1, sheet.getLastColumn()).getValues()[0];
// Convert the rowData to JSON format
var payload = JSON.stringify(rowData);
// Set the options for the POST request
var options = {
method: âpostâ,
contentType: âapplication/jsonâ,
payload: payload
};
// Send the POST request
UrlFetchApp.fetch(url, options);
}
and then you can activate like this:
To set up the function in your Google Sheets:
- Open your Google Sheets document.
- Go to the menu bar and click on âExtensionsâ, then select âApps Scriptâ.
- In the Apps Script editor, paste the provided code.
- Save the script by clicking on the floppy disk icon or by pressing Ctrl + S.
- Name your project by clicking on the âUntitled projectâ text and entering a name of your choice.
- After saving, find the clock icon (Triggers) in the toolbar and click on it to create a trigger for the function.
- Click on the â+ Add Triggerâ button.
- Configure the trigger settings as follows:
- Choose the function name (âonEditâ) from the drop-down list.
- Select the event type as âOn editâ.
- Choose âHeadâ or âRunâ depending on your preference.
- Finally, click on the âSaveâ button.
From now on, whenever a row is updated in your Google Sheets document, it will trigger the onEdit
function. This function will then send a POST request to the specified URL, containing the updated row data. Donât forget to replace âhttps://example.com/apiâ with the actual URL where you want to send the POST request.
2 Likes