Hooks not working in Bulk type Smart Actions

Feature(s) impacted

Hooks don’t work on bulk type smart actions despite documentation: Use a Smart Action Form - Developer Guide

Observed behavior

Unless I specify type: 'single' for the action type, the following produces no response:

      hooks: {
        change: {
          Message: async ({ fields, record }) => {
            console.log(`load: / fields`, fields);
            console.log(`load: / request`, record);

            return fields;
          },
          Recruiter: async ({ fields, record }) => {
            console.log(`load: / fields`, fields);
            console.log(`load: / request`, record);

            return fields;
          }
        }
      },

Expected behavior

As noted in the documentation, the following should work just fine:

const { collection, RecordsGetter } = require('forest-express-sequelize');
const { customers } = require('../models');
const customersHaveSameCountry = require('../services/customers-have-same-country');

collection('customers', {
  actions: [{
    name: 'Some action',
    type: 'bulk',
    fields: [
      {
        field: 'country',
        type: 'String',
        isReadOnly: true
      },
      {
        field: 'city',
        type: 'String'
      },
    ],
    hooks: {
      load: async ({ fields, request }) => {
        const country = fields.find(field => field.field === 'country');
        
        const ids = await new RecordsGetter(forest, request.user, request.query)
          .getIdsFromRequest(request);
        const customers = await customers.findAll({ where: { id }});

        country.value = '';
        country.isReadOnly = false;
        
        // If customers have the same country, set field to this country and make it not editable
        if (customersHaveSameCountry(customers)) {
          country.value = customers.country;
          country.isReadOnly = true;
        }
        
        return fields;
      },
    },
  }],
  fields: [],
  segments: [],
});

Can this be retested to make sure it does in fact work? I am not able to get load or change hooks to produce any response.

According to this older post, load hooks do not work for bulk actions:

But again, the documentation says otherwise.

Context

  "meta": {
    "liana": "forest-express-sequelize",
    "liana_version": "7.12.3",
    "stack": {
      "database_type": "postgres",
      "engine": "nodejs",
      "engine_version": "17.9.0",
      "orm_version": "6.11.0"
    }
  }

Hello @David_Panzarella,

According to the changelog of forest-express-sequelize, hooks support on bulk and global actions has been introduced with forest-express-sequelize@8.0.0.

As you are using an earlier version, this feature is not supposed to work with your version.

You can follow this documentation about upgrading from v7 to v8, and you’ll be able to use hooks on bulk actions.

Ah, i see. I saw the 8.0 note only on the Add/Remove fields dynamically above:

Should probably move it up, and relabel as: The following features are only available…

Thanks for the feedback, we’ll see how to improve the docs.