Assemble OSHA 300-ready rows from recordable incidents with sequential case numbers for the calendar year. The workbook becomes the system of record; Apps Script owns the joins and business rules so analysts are not pasting monthly formulas.
Entry point `buildOsha300Prep` reads typed columns with SpreadsheetApp batch APIs. SpreadsheetApp is the primary service; Time-driven describes how you usually invoke it after authorization.
Keep thresholds (grace days, bands, alert emails, API keys) in Config cells or Script Properties so the same .gs file promotes from sandbox to production without code edits.
This page is technical only: sheet layout, edge cases, runnable code, deploy steps, and FAQs for prepare osha 300 log rows from incidents. No consulting pitch—just the pattern you can paste and harden.
Need this built? Hire a Google Apps Script developer →
Sheet / project setup
| Tab | Columns | Notes |
|---|---|---|
| Incidents | Fields + Recordable Y/N | Source |
| Osha300 | CaseNo…Class | Year log |
What this script does
buildOsha300Prep() assemble OSHA 300-ready rows from recordable incidents with sequential case numbers for the calendar year.
- Recordable filter
- Annual case numbers
- Days away / restricted columns
Prerequisites
Container-bound script on the workbook that contains the tabs in the setup table. Authorize SpreadsheetApp scopes on first run.
- V8 runtime
- Exact sheet names
- Script timezone = ops timezone
Walkthrough
Filter calendar-year recordable incidents, assign CaseNo, write Osha300 with days-away and restricted columns.
Paste the code, set Config/Properties, run buildOsha300Prep once, verify the output tab, then attach a Time-driven trigger.
Edge cases
Non-recordable rows never enter Osha300; case numbers restart each calendar year run.
Testing
Use a sandbox copy with 3–5 known rows. Compute expected outputs for prepare osha 300 log rows from incidents offline, run buildOsha300Prep, and diff the output tab including one intentional bad row.
Hardening
Add LockService around multi-sheet writes if triggers can overlap. Log run timestamps. Keep API keys and alert emails in PropertiesService—not in shared cells.
Variations
Fork ideas: filter to one business unit, change grain (daily→weekly), or POST a summary payload after buildOsha300Prep succeeds.
Operations notes
Assign an owner for the output tab, document regenerate steps, and treat `buildOsha300Prep` as source of truth over ad-hoc cell formulas.
Full code: buildOsha300Prep()
Run buildOsha300Prep when source tabs are current. Edit sheet names and Config/Properties first.
function buildOsha300Prep(){
const ss=SpreadsheetApp.getActive();
const year=new Date().getFullYear();
const src=ss.getSheetByName('Incidents').getDataRange().getValues().slice(1);
const out=[];
let caseNo=1;
src.forEach(r=>{
const d=new Date(r[0]);
if(d.getFullYear()!==year) return;
const recordable=String(r[7]).toUpperCase()==='Y';
if(!recordable) return;
out.push([
caseNo++,
d,
r[1], // employee
r[2], // job title
r[3], // description
Number(r[4])||0, // days away
Number(r[5])||0, // restricted
r[6] // classification
]);
});
const sh=ss.getSheetByName('Osha300');
sh.clearContents();
sh.appendRow(['CaseNo','Date','Employee','JobTitle','Description','DaysAway','Restricted','Class']);
if(out.length) sh.getRange(2,1,out.length+1,8).setValues(out);
}- Line 1: Entry point — bind triggers to buildOsha300Prep.
- Line 4: Batch read; avoid per-cell getValue in loops.
- Line 26: Batch write output rows in one setValues call.
- Line 5: Rename sheet constants before production.
- Line 6: Rename sheet constants before production.
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: prepare osha 300 log rows from incidents
- 1Setup tabs exist with headers matching buildOsha300Prep
- 2Dry-run on a copy workbook
- 3Timezone verified
- 4SpreadsheetApp authorization completed
- 5Output spot-checked against hand calc
- 6Time-driven trigger added only after validation
- 7Owners + alert recipients documented
Frequently asked questions
At minimum the tabs listed in the setup table for Prepare OSHA 300 Log Rows from Incidents. Output tabs may be cleared each run—do not store source-of-truth data there.
Run from the Apps Script editor for dry runs. Production usually uses a Time-driven trigger after OAuth succeeds once.
Non-recordable rows never enter Osha300; case numbers restart each calendar year run.
Per-cell calls burn quota and wall time. One read + one write keeps this pattern under the 6-minute execution cap longer.
PropertiesService (Script Properties) for API keys and alert inboxes. Config sheet is fine for non-secret thresholds.
Simple ratios maybe; prepare osha 300 log rows from incidents needs joins, branching, or side effects (email/Docs/API) that Apps Script handles cleanly.
Keep the .gs in clasp/git. Avoid divergent copies of formulas on the output tab—regenerate from the script.