From ce4cf778887091aa95c93788d88bd3858c638e46 Mon Sep 17 00:00:00 2001 From: Saqib Date: Tue, 10 Nov 2026 14:50:47 +0530 Subject: [PATCH] Apps Script migration: merge duplicate Retired columns, keep both values on a clash --- scripts/cohort-apps-script/Code.gs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/cohort-apps-script/Code.gs b/scripts/cohort-apps-script/Code.gs index 01eb782f..4d487c21 100644 --- a/scripts/cohort-apps-script/Code.gs +++ b/scripts/cohort-apps-script/Code.gs @@ -176,17 +176,22 @@ function migrateUndpColumns() { }); headers.forEach(function (h, j) { if (h === 'Timestamp' || used[j] || h === '') return; - cols.push({ header: /^Retired: /.test(h) ? h : 'Retired: ' + h, from: [j] }); + var name = /^Retired: /.test(h) ? h : 'Retired: ' + h; + // An old-form submission after a migration recreates a retired column; fold it into the existing one. + var same = cols.filter(function (c) { return c.header === name; })[0]; + if (same) same.from.push(j); else cols.push({ header: name, from: [j] }); }); var out = values.map(function (row, r) { return cols.map(function (c) { if (r === 0) return c.header; - for (var k = 0; k < c.from.length; k++) { - var v = c.from[k] < 0 ? '' : row[c.from[k]]; - if (v !== '' && v != null) return v; - } - return ''; + // Merged columns: keep every distinct non-empty value, so a clash never drops an answer. + var vals = []; + c.from.forEach(function (j) { + var v = j < 0 ? '' : row[j]; + if (v !== '' && v != null && vals.indexOf(v) === -1) vals.push(v); + }); + return vals.length === 1 ? vals[0] : vals.join(' | '); }); }); sheet.clearContents();