Help

Re: Script to Find and Display all Broken Fields in a Base

1253 0
cancel
Showing results for 
Search instead for 
Did you mean: 
AlliAlosa
10 - Mercury
10 - Mercury

Hi all!

I wrote this script a couple of weeks ago and it’s been extremely useful for me, so I thought I’d share it here :smiling_face_with_halo: The script will find any “broken” fields - the ones that have the little red triangle next to the name - in your base, then display the field name, table, and any applicable field description.

There’s no need to change anything at all (unless you want to, of course). All you need to do is copy and paste the below into the scripting app, and click run :slightly_smiling_face:

const config = input.config({
    title: "🚨 Broken Field Report",
    description: "This script will find and display the table, field name, and description (if available) of all broken fields in the base.",
});

let title = "🚨 Broken Field Report";

let baseName = base.name;

/**********************************************************************************************************/
await main();
/**********************************************************************************************************/

async function main() {
    outputTitle(baseName, title);

    let tables = base.tables;

    let brokenFields = await findBrokenFields(tables);

    if (brokenFields.length) {
        output.markdown("### 🚨 " + brokenFields.length + " Broken Fields");
        output.table(brokenFields);
    } else {
        output.markdown("### ✅ Awesome! No Broken Fields");
    }
}

/**********************************************************************************************************/
async function findBrokenFields(tables) {
    let brokenFields = [];
    for (let table of tables) {
        let fields = table.fields;
        let computedFields = fields.filter(fld => (fld.isComputed));
        for (let fld of computedFields) {
            if (fld.options) {
                if (fld.options.hasOwnProperty("isValid")) {
                    if (!fld.options.isValid) {
                        brokenFields.push({
                            "Table": table.name,
                            "Field Name": fld.name,
                            "Description": fld.description
                        });
                    }
                }
            }
        }
    }
    return brokenFields;
}
/**********************************************************************************************************
 * HELPER FUNCTIONS
**********************************************************************************************************/

function outputTitle(title, subTitle1, subTitle2) {
    output.clear();
    output.markdown("# " + title);
    if (subTitle1) {
        output.markdown("## " + subTitle1);
    }
    if (subTitle2) {
        output.markdown("### " + subTitle2);
    }
}
1 Reply 1
Jeremie_Lambole
5 - Automation Enthusiast
5 - Automation Enthusiast

Works like a charm! thanks