DocsUpdated 22 Oct 2026
Fix unique ROWID values in a site
This API function identifies and optionally sets new ROWID values in a site if there are duplicates.
#/API/EnsureUniqueROWID.js
GET lists the duplicates without changing anything. POST with save=true corrects them — writing is never done on a GET, so a link cannot trigger it. Restrict the endpoint to administrators, and remove it when you are done.
// #/API/FixRowIds.js
export default (save) => {
// Only the site owner's team should run this. Replace with your own role check.
if (!request.user || !docly.allowModify("/", request.user)) return docly.denyAccess();
// Reading is safe on GET. Writing requires POST AND an explicit save=true.
let doSave = save === "true" || save === true;
if (doSave && request.method != "POST") throw new Error("Verb not supported");
let result = [];
let skipped = 0;
let files = docly.listFiles("/", "*", false, true, false);
let lookup = {};
for (let f of files) {
// Files without a schema have no ROWID fields — skip them. (Code files have the schema "Code File" and drop out later: they have no ROWID.)
if (!f.Schema) continue;
let o;
try { o = JSON.parse(f.Values); } catch (e) { skipped++; continue; }
if (!o || !o.ROWID) continue;
if (lookup[o.ROWID]) {
if (doSave) docly.patchFile(f.Path, { "ROWID": docly.guid() });
result.push({ "file1": f.Path, "file2": lookup[o.ROWID].Path });
}
else
lookup[o.ROWID] = f;
}
return {
"Duplicates": result,
"Corrected": doSave,
"Skipped": skipped
};
} Use this function to run once and ensure unique ROWID values within a site.