ui.prompt is enough when you need one or two values without building HtmlService forms.
This menu item asks for a row number, then a SKU, validates both, and writes Inventory column B plus a lastUpdated stamp in column E.
ButtonSet.OK_CANCEL lets users abort cleanly; always check getSelectedButton before reading text.
Keep regex rules next to the write so invalid SKUs never hit the sheet.
Need this built? Hire a Google Apps Script developer →
Sheet / project setup
| Sheet | Column | Purpose |
|---|---|---|
| Inventory | A Item | Existing item name |
| Inventory | B SKU | Updated by prompt |
| Inventory | E lastUpdated | Timestamp on change |
| Menu | Quick Input | onOpen menu |
What this script does
promptSkuForRow sequences two prompts, validates, writes, and alerts success.
Prerequisites
Bound script; Inventory sheet with at least columns B and E.
- Row 1 headers
- Data starts row 2
- Users know target row numbers
Walkthrough
Choose Quick Input → Set SKU on row, enter 2 and ABC-100, confirm B2/E2 update.
Edge cases
Non-integer row strings become NaN and fail the integer check.
- Cancel exits silently
- SKU normalized to uppercase
How to test
Try row 1, bad SKU characters, and cancel on the second prompt.
Hardening for production
Look up row by item name instead of number; log changes to Audit.
Variations
ui.alert for confirmations; showModalDialog when you need more fields.
Full code: promptSkuForRow()
Reload the Sheet to load the menu, then run Set SKU on row with a real Inventory row.
/**
* Prompt dialogs for quick single-value input from a custom menu.
*/
function onOpen() {
SpreadsheetApp.getUi()
.createMenu("Quick Input")
.addItem("Set SKU on row...", "promptSkuForRow")
.addToUi();
}
function promptSkuForRow() {
const ui = SpreadsheetApp.getUi();
const rowResp = ui.prompt(
"Target row",
"Enter the row number to update (header is row 1):",
ui.ButtonSet.OK_CANCEL
);
if (rowResp.getSelectedButton() != ui.Button.OK) return;
const row = Number(rowResp.getResponseText());
if (!Number.isInteger(row) || row < 2) {
ui.alert("Row must be an integer >= 2");
return;
}
const skuResp = ui.prompt("SKU", "Enter the SKU code:", ui.ButtonSet.OK_CANCEL);
if (skuResp.getSelectedButton() != ui.Button.OK) return;
const sku = skuResp.getResponseText().trim().toUpperCase();
if (!/^[A-Z0-9-]{3,20}$/.test(sku)) {
ui.alert("SKU must be 3–20 chars A–Z, 0–9, or hyphen");
return;
}
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Inventory");
sheet.getRange(row, 2).setValue(sku); // column B
sheet.getRange(row, 5).setValue(new Date()); // column E lastUpdated
ui.alert("Updated row " + row + " to SKU " + sku);
}- Line 13: Opens a modal prompt dialog.
- Line 18: Ignores Cancel / close without writing.
- Line 21: Rejects blank or fractional row numbers.
- Line 35: Writes SKU to column B.
- Line 22: Confirms the update to the user.
Deploy this example
- 01
Open Apps Script
In the bound spreadsheet: Extensions → Apps Script. For standalone projects, create one at script.google.com and link your Sheet by ID.
- 02
Paste and save
Add a .gs file, paste the code below, rename constants at the top (sheet names, column letters, API property keys), then save.
- 03
Authorize once
Run the main function from the editor. Accept OAuth scopes when prompted — triggers cannot run until authorization succeeds once.
- 04
Add the trigger
Triggers → Add trigger → choose the handler function and event (time-driven, on edit, or on form submit). Delete test triggers before production.
Before you run: prompt dialogs
- 1Inventory sheet exists
- 2Column B is the SKU column
- 3Reload spreadsheet for onOpen menu
- 4Authorize on first menu use
- 5Document SKU format for users
- 6Test Cancel paths
Frequently asked questions
No — SpreadsheetApp.getUi prompts only work in the Sheets UI container, not HtmlService web apps.
prompt does not take a default text box value; pre-fill via HTML dialogs instead.
Use ui.alert with YES_NO ButtonSet.
Normalization avoids duplicate SKUs that differ only by case.
Accept a string and parse with Utilities.formatDate validation, or use a custom HTML dialog date picker.
Yes — script execution waits until the user dismisses the dialog.
More than two or three fields usually deserves HtmlService.