Google form Data sync in webhook flow
Faizal
#1
Faizal
Hi sir, the data which is coming through google form in google sheets not capture in workflow.

After struggling a lot I found few things that need to be change and then it resolved.

Google form by default create a sheet name - So, the exact sheet name required to match. If we change the name as Sheet1 then data will not added through form.
Also, those data who submitted through google form to google sheets, it not triggered with the existing code.

So, here I made few changes on code and it working well. Request to add a shortcut in platform so, people get benefit of it. Thank you

function onFormSubmit(e) {
var sheet = e.source.getActiveSheet();

// Check if the active sheet is "Form Responses 3"
if (sheet.getName() === "Form Responses 3") {
var lastRow = sheet.getLastRow(); // Get the last row of the sheet (newly submitted row)
var rowData = sheet.getRange(lastRow, 1, 1, sheet.getLastColumn()).getValues()[0]; // Get the data of the submitted row

sendToWebhook(lastRow, rowData, 'FORM_SUBMIT'); // Send the data of the submitted row
}
}

// Example function to send data to a webhook
function sendToWebhook(rowNumber, rowData, type) {
var webhookUrl = "https://dash.botwaba.com/webhook/whatsapp-workflow/xxxxxxxxxxxxxxxxxxxxxxxxx"; // Replace with your actual webhook URL
var payload = {
'rowNumber': rowNumber,
'rowData': rowData,
'type': type
};

var options = {
'method': 'post',
'contentType': 'application/json',
'payload': JSON.stringify(payload)
};

UrlFetchApp.fetch(webhookUrl, options);
}
#2
BotSailor
hank you for bringing up this observation regarding Google Forms and Google Sheets integration for workflows. We truly appreciate your effort in identifying the issue and even sharing the workaround code.

You're absolutely right that Google Forms creates its default sheet name when linked, and any renaming or mismatch in sheet names can cause disruptions in data syncing. Additionally, form submissions directly append rows programmatically, which may not trigger traditional spreadsheet change events like onChange.

To address this effectively, we recommend using the onFormSubmit trigger in Google Apps Script. This trigger is specifically designed to handle new rows added by Google Forms submissions, ensuring data is captured and sent to the webhook seamlessly. Here's a refined approach to streamline the process:



And your code is correct for Google Form Submit.

Thanks
#3
Faizal
Yes, I am using the same code for it onFormSubmit. It work perfectly. Thank you