# Smart collection hooks load record

**URL:** <https://community.forestadmin.com/t/smart-collection-hooks-load-record/2382>\
**Category:** Help me!\
**Created:** [April 27, 2021, 4:22pm UTC](https://community.forestadmin.com/t/smart-collection-hooks-load-record/2382 "2021-04-27T16:22:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [April 27, 2021, 4:22pm UTC](https://community.forestadmin.com/t/smart-collection-hooks-load-record/2382/1 "2021-04-27T16:22:09Z")

</div>

This topic follows [Smart collection hooks routes](https://community.forestadmin.com/t/smart-collection-hooks-routes/2303)

Today I updated forest-express-sequelize to v7.6.3

As for now, this is my smart collection forest/ file :

```javascript
const { collection } = require('forest-express-sequelize');

collection('categories', {
  actions: [{
    name: 'Ajouter un nouveau contrat',
    type: 'single',
    fields: [{
      field: 'Clef de repartition',
      type: 'Enum',
      enums: []
    }, {
      field: 'Référence',
      type: 'String'
    }, {
      field: 'Date de début',
      type: 'Date'
    }, {
      field: 'Date de fin',
      type: 'Date'
    }, {
      field: 'Préavis en jours',
      type: 'Number'
    }, {
      field: 'Tacite reconduction',
      type: 'Boolean'
    }, {
      field: 'Montant annuel',
      type: 'Number'
    }, {
      field: 'comment',
      type: 'String'
    }, {
      field: 'Échéance du contrat assurance',
      type: 'Enum',
      enums: [
        'Mensuelle',
        'Trimestrielle',
        'Annuelle'
      ]
    }, {
      field: 'Type de contrat',
      type: 'Enum',
      enums: [
        'Maintenance',
        'Assurance'
      ]
      // }, {
      // "provider_matricule": "TYMATE_12"
    }],
    hooks: {
      load: ({ fields, record }) => {
        console.log(record);
        return fields;
      }
    }
  }, {
    name: 'Mise à jour (avenant) d\'un contrat',
    type: 'single',
    fields: [{
      field: 'Date de fin',
      type: 'String'
    }, {
      field: 'Préavis en jours',
      type: 'String'
    }, {
      field: 'Tacite reconduction',
      type: 'Boolean'
    }, {
      field: 'Montant',
      type: 'Number'
    }, {
      field: 'PJ du contrat',
      type: 'File'
    }, {
      field: 'Échéances',
      type: 'String'
    }],
  }],
  fields: [{
    field: 'id',
    type: 'String'
  }, {
    field: 'display_name',
    type: 'String'
  }, {
    field: 'created_at',
    type: 'Date'
  }, {
    field: 'updated_at',
    type: 'Date'
  }, {
    field: 'sergic_slug',
    type: 'String'
  }, {
    field: 'sergic_update_time',
    type: 'Date'
  }, {
    field: 'mandatory',
    type: 'Boolean'
  }, {
    field: 'default',
    type: 'Boolean'
  }]
});

```

As you can see, the whole point of upgrading forest-express-sequelize was in order to use hooks load method in the smart action of a smart collection. I’m about to write the load method in order to init the dropdowns in my form.

But I’m really puzzled about one thing :

```javascript
 load: ({ fields, record }) => {
        console.log(record);
        return fields;
      }

```

This console.log simply displays :

```javascript
{ id: '101' }

```

but this is FAR from what I need in my load method :  
I should have the _display\_name_, _mandatory_ and all additional fields that might come in the future (the API providing me data for this collection will soon be enriched).  
If the “record” contains the _id_ only, it might be a major issue for me.

I should specify that i’m calling the smart action from the table view and I do not have a GET method for a unique record (hense no summary view).

---

<div class="post-metadata">

**Author:** ![arnaud](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaud/32/32_2.png) [@arnaud](https://community.forestadmin.com/u/arnaud)\
**Post date:** [April 27, 2021, 4:31pm UTC](https://community.forestadmin.com/t/smart-collection-hooks-load-record/2382/2 "2021-04-27T16:31:48Z")

</div>

Hi @JeremyV,

The behaviour you describe is the one that was designed.  
In the context of a Smart Collection, so far, there is no easy way for the agent to retrieve the full Smart Collection record (ie you implement the controllers logic manually)

As a developer, you know the logic to build your Smart Collection record.  
And I think the `id` is sufficient to compute the whole record in the hook before using it.  
Is it wrong to say so in your context?

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [April 27, 2021, 5:01pm UTC](https://community.forestadmin.com/t/smart-collection-hooks-load-record/2382/3 "2021-04-27T17:01:12Z")

</div>

I’m afraid so. My API provider is providing me additional info that is not existing in the DB. These are computed business logic. This is why the smart collection has been created in the first place.

For instance : `Clef de repartition` - this field is a dropdown list which is different from one place to another ; so my API provider will add an additional attribute in the GET all route which is the `place_id` so I can query the DB and construct the appropriate list.

This is one example ; before posting my form in the smart action route, i may have to set this `place_id` field back to my API provider, so I need to have kept the information all along.

---

<div class="post-metadata">

**Author:** ![Guillaume\_Cisco](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaume_cisco/32/918_2.png) [@Guillaume\_Cisco](https://community.forestadmin.com/u/Guillaume_Cisco)\
**Post date:** [April 28, 2021, 9:33am UTC](https://community.forestadmin.com/t/smart-collection-hooks-load-record/2382/4 "2021-04-28T09:33:40Z")

</div>

Hello @JeremyV,

From the way smart collection work, we are not able to fetch the record.  
The only information we get is the id.  
You will need to fetch the record from the id inside the hook.

I hope it can help you

---

<div class="post-metadata">

**Author:** ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)\
**Post date:** [April 28, 2021, 3:55pm UTC](https://community.forestadmin.com/t/smart-collection-hooks-load-record/2382/5 "2021-04-28T15:55:00Z")

</div>

Thank you for your input, we’ll figure out another way to proceed.
