← back to Filemaker Mcp
scripts/bulk-set-dwnumber-fm.mjs
27 lines
// Set the DW Number (JS Pattern) + vid=GREEN on the Greenland cork WALLPAPER records.
// DW SKU becomes DWGL-<num> (num = 500000 + i*10). Matches on Mfr Pattern (the real code).
// Reads the canonical map from greenland-onboard/data/dwgl-map.json.
// node bulk-set-dwnumber-fm.mjs --apply
import { readFileSync } from 'node:fs';
import * as fm from '../src/fm-client.js';
const APPLY = process.argv.includes('--apply');
const ENTRY = 'Add wallcovering', FULL = '*List Wallpapers - Full View';
const map = JSON.parse(readFileSync(process.env.HOME + '/Projects/greenland-onboard/data/dwgl-map.json', 'utf8'));
const sleep = ms => new Promise(r => setTimeout(r, ms));
let ok = 0, skip = 0, fail = 0;
console.log(`${map.length} DWGL products · ${APPLY ? 'APPLY' : 'DRY-RUN'}`);
for (const m of map) {
const r = await fm.findRecords('WALLPAPER', FULL, { 'Mfr Pattern': '==' + m.mfr, vid: 'GL' }, { limit: 1 }).catch(() => ({ records: [] }));
const rec = r.records?.[0];
if (!rec) { skip++; if (skip <= 5) console.error(` ? no record for mfr ${m.mfr}`); continue; }
if (!APPLY) { if (ok < 5) console.log(` ${m.mfr} → JS Pattern=${m.num} vid=GREEN (${m.dwsku})`); ok++; continue; }
try {
await fm.updateRecord('WALLPAPER', ENTRY, rec.recordId, { 'JS Pattern': m.num, vid: 'GREEN' }, { dryRun: false });
// price + sold-per live on the Full View layout
try { await fm.updateRecord('WALLPAPER', FULL, rec.recordId, { 'Retail Price': '59.50', 'Sold Per': 'Yard' }, { dryRun: false }); } catch {}
ok++; if (ok % 25 === 0) console.log(` ...${ok}`); await sleep(90);
} catch (e) { fail++; console.error(` FAIL ${m.mfr}: ${e.fmCode || e.message}`); await sleep(250); }
}
console.log(`\nDONE. updated=${ok} skipped=${skip} fail=${fail}`);