Formula to count checkboxes in description

Hi all, for some projects I don’t need the full scope of project/task database and sometimes use the simple checkboxes directly in the description. However it can be difficult to know what entities contain these checkboxes.

Is anyone aware of a formula that could find/count complete/incomplete checkboxes that are in Descriptions/Rich Text fields?

1 Like

I don’t think it’s possible with formulas I’m afraid.
However, you can use an automation to calculate how many ticked/unticked checkboxes there are (and put the result in some fields of your choice):

const fibery = context.getService('fibery');

for (const entity of args.currentEntities) {
    const content = await fibery.getDocumentContent(entity['Description']['Secret'], 'md');
    const tickedregex = /- \[x\]/g
    const ticked = content.match(tickedregex);
    const untickedregex = /- \[ \]/g
    const unticked = content.match(untickedregex);
    await fibery.updateEntity(entity.type, entity.id, { 'Ticked': ticked.length, 'Unticked': unticked.length });
}

This looks in the Description field and puts the counts of ticked/unticked as values in the ‘Ticked’ and ‘Unticked’ number fields.

You could have this run as an automation that triggers whenever there is an update to the Description field.

4 Likes

We have a similar situation. I updated the fields names to match our use case and the script worked like an absolute charm. Thanks a lot

2 Likes