Trigger a smart action on the first record of a collection without having to select a record

Hello,

I would like to create a smart action for my team that would automatically select the first record of the collection. Basically I don’t want to give the choice to the agent to decide on which record he will apply the smart action.

As of today, it looks like smart actions only work when a record is selected.

Could you help us solve our issue?

Hi @Amaury_Chaboche1

Welcome to the forest community

Would creating a global smart action which will be available when no records are selected but executes on the first record of the collection suit your need?

(This sample is using agent-nodejs, I don’t know which agent you are running)

  agent.customizeCollection('customer', collection => {
    collection.addAction('Send email', {
      scope: 'Global',
      execute: async (context, resultBuilder) => {
        // Get the first record of the collection
        // use the context.filter object to get information about the current selected segment if
        // you need it.
        const [firstRecord] = await context.collection.list(
          {
            sort: [{ field: 'id', ascending: true }],
            page: { skip: 0, limit: 1 },
          },
          ['id', 'name'],
        );

        // Do stuff here
        // ...

        // Show a success notification
        return resultBuilder.success(`Email sent to ${firstRecord.name}`);
      },
    });
  });