← back to Filemaker Mcp

scripts/bulk-series-cork-to-dwgl.mjs

22 lines

// Update the Greenland cork WALLPAPER records: Series 'CORK' -> 'DWGL' so the DW SKU
// (combo sku) becomes DWGL-<mfr>. Idempotent (finds remaining CORK+GL rows each pass).
//   node bulk-series-cork-to-dwgl.mjs --apply
import * as fm from '../src/fm-client.js';
const APPLY = process.argv.includes('--apply');
const ENTRY = 'Add wallcovering', FULL = '*List Wallpapers - Full View';
const sleep = ms => new Promise(r => setTimeout(r, ms));

let ok = 0, fail = 0;
for (let pass = 0; pass < 20; pass++) {
  const r = await fm.findRecords('WALLPAPER', FULL, { Series: '==CORK', vid: 'GL' }, { limit: 100 }).catch(() => ({ records: [] }));
  const recs = r.records || [];
  if (!recs.length) break;
  console.log(`pass ${pass + 1}: ${recs.length} CORK records`);
  if (!APPLY) { console.log('DRY-RUN — pass --apply'); break; }
  for (const rec of recs) {
    try { await fm.updateRecord('WALLPAPER', ENTRY, rec.recordId, { Series: 'DWGL' }, { dryRun: false }); ok++; if (ok % 25 === 0) console.log(`  ...${ok}`); await sleep(90); }
    catch (e) { fail++; console.error(`  FAIL ${rec.recordId}: ${e.fmCode || e.message}`); await sleep(250); }
  }
}
console.log(`\nDONE. updated=${ok} fail=${fail}`);