Filtering with Modular Content field in the admin Content UI

Hi :sunny:

We got around 1900+ records, and are doing the data filling step :slight_smile:
We found a mistake where one of the modular content fields (we use it for breadcrumbs in case there is more than 1) are empty.

Now to correct it, we need to filter all the records with this Modular Content type field, and show all the records that have that field empty.

The issue is it seems that the Modular Content field type isn’t shown in the filter list of keys possible to filter with in the Search bar.

Any help is super appreciated! :slight_smile:
:bowing_man:

Hello @veljko,

unfortunately, behind the scenes, this is the same issue as this one: Deep filtering on both CMA and CDA

To work around this you might need to use our APIs with a script a search yourself through the blocks. We want to add this functionality in the CMS soon, but for now you need to do it yourself, sorry :frowning:

1 Like

This should work!

const { SiteClient } = require('datocms-client');

(async () => {
  try {
    const client = new SiteClient(
      'YOUR_API_TOKEN',
    );

    const records = await client.items.all(
      {
        filter: { type: "<YOUR MODEL NAME>" },
      },
      { allPages: true },
    );

    for (const record of records) {
      if (record.yourModularContent.length === 0) {
        console.log('Empty modular content on record ' + record.id);
      }
    }
  } catch (e) {
    console.log(e);
  }
})();
1 Like

Got it! No worries, I am sure you have 10000 feature creeps!
Finest CMS on the planet still!

1 Like

Thanks for saving me time!! :bowing_man:

1 Like