Broken Smart Action: change hook not working

Feature(s) impacted

We have a smart action form with a change hook. The change hook implements some changes to the other form fields. This feature worked without problem for a long time and this issue appeared suddenly today without any changes from our side. Here is the source:

...
actions: [
    {
      name: 'Close the case',
      type: 'single',
      fields: [
        {
          field: 'template',
          description: 'E-mail message template to send to the client',
          type: 'Enum',
          enums: [
            'No E-mail',
            'Refer to Legal Help',
            'Refer to Police/Prosecutor',
            'Refer to AsyLex',
            'Refer to SozialHilfe',
            'No Referral',
          ],
          isRequired: true,
        },
        {
          field: 'greeting',
          type: 'String',
          isReadOnly: true,
        },
        {
          field: 'message',
          type: 'String',
          widget: 'text area',
        },
        {
          field: 'regards',
          type: 'String',
          isReadOnly: true,
          widget: 'text area',
        },
      ],
      hooks: {
        load: ({ fields, _ }) => {
          fields['template'].value = 'No E-mail';
          fields['message'].isReadOnly = true;
          return fields;
        },
        change: {
          template: ({ fields, _ }) => {
            console.log('l');
            let messageTemplate = null;
            const template = fields['template'].value;
            fields['message'].isReadOnly = false;
            switch (template) {
              case 'Refer to Legal Help':
                messageTemplate =
                  'Wir empfehlen Ihnen, sich das Angebot des Vereins Legal Help unter www.verein-legal-help.ch anzusehen. Allenfalls haben Sie im Rahmen dieses Angebots Anspruch auf eine kostenlose Erstberatung.';
                break;
              case 'Refer to Police/Prosecutor':
                messageTemplate =
                  'Da in Ihrem Fall möglicherweise Straftaten begangen wurden, empfehlen wir Ihnen, sich in einem ersten Schritt an die Polizei und/oder an die Staatsanwaltschaft zu wenden.';
                break;
              case 'Refer to AsyLex':
                messageTemplate =
                  'Wir empfehlen Ihnen, sich das Angebot des gemeinnützigen Vereins AsyLex unter www.asylex.ch anzusehen. AsyLex ist auf die Bearbeitung von Fällen im Asylrecht spezialisiert und kann Sie möglicherweise unterstützen.';
                break;
              case 'Refer to SozialHilfe':
                messageTemplate =
                  'Wir empfehlen Ihnen, sich das Angebot des UFS (Unabhängige Fachstelle für Sozialhilferecht) unter https://www.sozialhilfeberatung.ch/ anzusehen. Allenfalls haben Sie im Rahmen dieses Angebots Anspruch auf eine kostenlose Erstberatung.';
                break;
              case 'No Referral':
                messageTemplate = '';
                break;
              default:
                fields['greeting'].value = '';
                fields['message'].value = '';
                fields['message'].isReadOnly = true;
                fields['regards'].value = '';
                return fields;
            }

            const message = [];
            message.push(
              'Leider hat sich bisher keine Anwältin/kein Anwalt auf Ihre Anfrage gemeldet. Wir haben Ihren Fall daher nun geschlossen.'
            );
            if (messageTemplate && messageTemplate.length) message.push(messageTemplate);

            const regards = [];
            regards.push('Wir wĂĽnschen Ihnen alles Gute./Nous vous souhaitons bonne chance./...');
            regards.push('Freundliche GrĂĽsse/Bien cordialement,/...');
            regards.push("Ihr Jurata-Team/L'équipe Jurata/...");
            regards.push('info@jurata.ch');
            regards.push('Jurata AG | Rieterstrasse 6, 8002 ZĂĽrich | www.jurata.ch');

            fields['greeting'].value = 'Guten Tag/Bonjour/...';
            fields['message'].value = message.join('\n\n');
            fields['regards'].value = regards.join('\n\n');

            return fields;
          },
        },
      },
    }
]
...

Observed behavior

When changing the field for which a change hook is registered, no call is being made to our server, instead the typeerror from below appears.

Expected behavior

No Typeerror, a call to our server, and the change hook succesfully completing.

Failure Logs

From the browser

client-47f1f74e7a684d8ef8ed9f8b533b4e30.js:1 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'attributes')
    at e.requestAgentHookWithContext (client-47f1f74e7a684d8ef8ed9f8b533b4e30.js:1:3275646)
    at e.triggerHook (client-47f1f74e7a684d8ef8ed9f8b533b4e30.js:1:3275850)
    at invoke (vendor-d090e5c62b54db7a841f6a16ca9727ed.js:58:418835)
    at d.flush (vendor-d090e5c62b54db7a841f6a16ca9727ed.js:58:417895)
    at p.flush (vendor-d090e5c62b54db7a841f6a16ca9727ed.js:58:419675)
    at B._end (vendor-d090e5c62b54db7a841f6a16ca9727ed.js:58:424760)
    at B.end (vendor-d090e5c62b54db7a841f6a16ca9727ed.js:58:421851)
    at B._runExpiredTimers (vendor-d090e5c62b54db7a841f6a16ca9727ed.js:58:426036)

Context

  • Project name: jurata
  • Team name: jurata
  • Environment name: all of them
  • Agent (forest package) name & version: “forest-express”: “^7.4.0”,
  • Database type: mongoose
  • Recent changes made on your end if any: none

Hello @David_Roegiers,

Thanks for sharing this very detailed report. We’ll check and get back to you.

1 Like

Hello @David_Roegiers,

We have reverted the potential culprit and our team still investigating on fixing the initial issue.

In the meanwhile, is it back to normal on your side? :pray:

Kind regards,
Morgan

1 Like

Hi @GuillaumeGautreau @morganperre

Thanks for the quick reaction and the reversion. It is back to normal on our side.

Marking the post above as a solution.

:+1:

1 Like

Thank you for your quick feedback too.

I will let the team know that they are on the right way to fix the regression.

:pray: