Dynamic value on Collection type form field

Feature(s) impacted

Smart action form field when setting type “Collection”.

Observed behavior

I tried to set the id as the value of the “Collection” form field. But it looks like I’m not doing the right thing. I also look for examples on the NodeJS agent documentation but I couldn’t find one.

        type: 'Collection',
        collectionName: 'ModelTemplateFamily',
        label: 'Family',
        defaultValue: async context =>
          (await context.getRecord(['familyId'])).familyId,

Expected behavior

Fill the form “Collection” field with a default value.

Failure Logs

 value?.join is not a function 

TypeError: value?.join is not a function
    at Function.valueToForest (/***/forest-admin-backend/node_modules/@forestadmin/agent/dist/utils/forest-schema/action-values.js:103:27)
    at Function.buildFieldSchema (/***/forest-admin-backend/node_modules/@forestadmin/agent/dist/utils/forest-schema/generator-actions.js:38:48)
    at /***/forest-admin-backend/node_modules/@forestadmin/agent/dist/routes/modification/action/action.js:107:69
    at Array.map (<anonymous>)
    at ActionRoute.handleHook (/***/forest-admin-backend/node_modules/@forestadmin/agent/dist/routes/modification/action/action.js:107:28)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)


  • Project name: Inarix
  • Environment name: Development
  • Agent type & version: NodeJS 1.7.1

From memory, I think this may be due to the fact that the agent expects an array.

Can you try like this?

defaultValue: async context => [await context.getRecord(['familyId'])).familyId],

This was coded like this to make it possible to handle composite ids, but is clearly counter intuitive.

If that works, I’ll add a ticket to either improve the doc or improve the API (or at least, throw a proper error…)

1 Like

Thanks a lot! That was it :scream: