Fix unique ROWID values in a site Last updated: 02. Sep 2025

This API function identifies and optionally sets new ROWID values in a site if there are duplicates.

#/API/EnsureUniqueROWID.js

Remember to add "save=true" to the query string to actually save changes.

(save) => {
    
    let result = [];
    let files = docly.listFiles("/", "*", false, true, false);
    let lookup = {};
    for(let f of files) {
        let o = JSON.parse(f.Values);
        if (!o.ROWID) continue;
        
        if (lookup[o.ROWID]) {
            // Crash identified
            if (save) 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" : !(!save)
    };
};

Use this function to run once and ensure unique ROWID values within a site.