Pre-fill field options from Google Sheets

Pre-fill field options with dynamically pulled data from a Google Sheet


This rule runs as the first step of the form is loaded. It queries a Google Sheet that has a Class Name header and several class names defined below, within the same column. The class names are then set as options of the CoursesDropdown field.

Rule Logic

function fetchSheetData(spreadsheetId, sheetName, apiKey, callback) {
    // API endpoint URL
    const url = `${spreadsheetId}/values/${sheetName}?key=${apiKey}`;

    // Fetch data from Google Sheets
        .then(response => response.json())
        .then(data => callback(data.values)); // Return the sheet values

function convertToJSON(data) {
    const [headers, ...rows] = data;
    return => {
        let obj = {};
        headers.forEach((header, index) => obj[header] = row[index]);
        return obj;

// Usage
const API_KEY = 'DUMMY_KEY'; // Replace with your Google Sheets API Key
const SPREADSHEET_ID = 'DUMMY_ID'; // Replace with your spreadsheet ID
const SHEET_NAME = 'Sheet1'; // Replace with your sheet name

fetchSheetData(SPREADSHEET_ID, SHEET_NAME, API_KEY, (data) => {
    const jsonData = convertToJSON(data)
    const classes = => account["Class Name"])
    CoursesDropdown.options = classes

Last updated