Zoho Forms allows you to dynamically prefill form fields with data fetched from external sources. One popular use case is pulling customer data stored in a Google Sheet and pre-populating your forms when the user opens them. This saves time, reduces errors, and improves the user experience.
In this article, we’ll walk you through the step-by-step process of setting up a Google Sheets Apps Script, deploying it as a web app, and integrating it with Zoho Forms via Dynamic Prefill Webhooks.
Open the Google Sheet where your data is stored.
From the top menu, click:
Extensions → Apps Script.
This will open the Apps Script editor in a new tab.
Copy and paste the following script:
function doGet(e) {
const sheetId = "{sheet_id}"; // <-- Replace with your real sheet ID
const sheetName = "Sheet1";
const columnToSearch = 1; // e.g., Column B = 2
const query = e.parameter.query || ""; // Example: ?query=Doe
if (!query) {
return ContentService
.createTextOutput(JSON.stringify({ message: "Missing search query" }))
.setMimeType(ContentService.MimeType.JSON);
}
const ss = SpreadsheetApp.openById(sheetId);
const sheet = ss.getSheetByName(sheetName);
const data = sheet.getDataRange().getValues();
for (let i = 0; i < data.length; i++) {
const cellValue = data[i][columnToSearch - 1].toString();
if (cellValue.includes(query)) {
const result = {
row: i + 1, // Optional: 1-based row number
data: data[i] // Entire matching row
};
return ContentService
.createTextOutput(JSON.stringify(result))
.setMimeType(ContentService.MimeType.JSON);
}
}
return ContentService
.createTextOutput(JSON.stringify({ message: "No matching row found." }))
.setMimeType(ContentService.MimeType.JSON);
}
Copy the sheetId from your Google Sheet URL as shown.
Replace the sheetId from your Google Sheet URL.
Replace the name of the sheet as shown with the sheet name.
Replace the column where your unique identifier (e.g., email, ID) is stored. Use numbers:
For example, if you want to search by email stored in column B, set: const columnToSearch = 2;
Under Select type, choose Web app.
Fill out the details:
Description: Enter something like Fetch data API.
Execute as: Me (your account).
Who has access: Anyone.
Click Deploy.
The first time you deploy, Google will ask for permissions. Click Authorize.
After deployment, Google will provide you with a Web App URL.
You can test the script in your browser with a value from your sheet’s search column.
It will return a JSON response containing that row’s data.
Open your form builder in Zoho Forms. Go to Settings > Form Settings > Prefill > Dynamic Prefill Webhook.
Under Webhook Settings, select Employee ID as the Search Field. Make sure the field you select here matches the column you set as columnToSearch in your Google Script.
Under Webhook URL, paste the Web App URL you copied.
Enter the Record Identifier as query. Click Next
Test the webhook with search field value like 1002 and check if the received response is valid.
Map the fields from your sheet’s response to the corresponding form fields.
Click Save.
Now, when a respondent opens the form, enters their Employee ID and clicks the search icon, the form will call the Google Sheet, fetch details, and prefill the form automatically.
Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.
If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.
You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.