# Regarding fetch new collection ids

**URL:** <https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984>\
**Category:** Help me!\
**Tags:** howtos\
**Created:** [July 26, 2021, 6:08am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984 "2021-07-26T06:08:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mayur\_Malaviya](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mayur_malaviya/32/2638_2.png) [@Mayur\_Malaviya](https://community.forestadmin.com/u/Mayur_Malaviya)\
**Post date:** [July 26, 2021, 6:08am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/1 "2021-07-26T06:08:09Z")

</div>

Hello guys,

Hope you are doing well,  
Suppose, I have two collection users, promocodes. I want to send specific promocode to selected users. How can I do that? I will eaither send mail or text msg but my concern is how to connect promocodes and users?

 ![promo](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/8/8cf19cde16242c49087903ce144b9363ad85a9e5.png)

 ![users](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/5/538ab8a523526638b4ebfc56e43b837f7faf3ab5.png)

---

<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:** [July 26, 2021, 8:19am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/2 "2021-07-26T08:19:38Z")

</div>

Hello @Mayur_Malaviya 👋

I think the best way to achieve what you are looking for is to use smart actions!

Check the documentation on how to [create and manage Smart Actions](https://docs.forestadmin.com/documentation/reference-guide/actions/create-and-manage-smart-actions)

Tell me if it helps 😉

---

<div class="post-metadata">

**Author:** ![Mayur\_Malaviya](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mayur_malaviya/32/2638_2.png) [@Mayur\_Malaviya](https://community.forestadmin.com/u/Mayur_Malaviya)\
**Post date:** [July 26, 2021, 8:33am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/4 "2021-07-26T08:33:57Z")

</div>

@Guillaume_Cisco I have already created many smart actions in my project, so as I understand my requirement, smart action won’t help me because it will help if I would like to perform action on specific raw of that collection only but my requirement is different.  
After selecting promocode, I would like to send that promocode to specific user, so whole list of users will be shown and I will choose either all or some users then send the promocode to them.  
Please, suggest me other way or in smart action if I left anything.

Thanks

---

<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:** [July 26, 2021, 8:56am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/5 "2021-07-26T08:56:49Z")

</div>

Smart Actions is the key here.  
Either you put a smart action on your users collection and you select users to send promocodes.  
Or, you put a smart action on your promocodes collection which I do not recommend as listing users in your smart action form will be very resource consuming.

Are you familiar with [smart action forms](https://docs.forestadmin.com/documentation/reference-guide/actions/create-and-manage-smart-actions/use-a-smart-action-form)?

---

<div class="post-metadata">

**Author:** ![Mayur\_Malaviya](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mayur_malaviya/32/2638_2.png) [@Mayur\_Malaviya](https://community.forestadmin.com/u/Mayur_Malaviya)\
**Post date:** [July 26, 2021, 9:11am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/6 "2021-07-26T09:11:19Z")

</div>

@Guillaume_Cisco Nice suggestions. Yes, I am familiar with smart action forms.  
As you suggest let us keep smart action forms on my users collection but now issue is that suppose I have 5 promocodes in that collection and some of them are expired. Now, I would like to send specific promocodes. How can I do that?

---

<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:** [July 26, 2021, 9:25am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/7 "2021-07-26T09:25:28Z")

</div>

You will need to filter the promocodes by the non expired ones.  
Have a look at the [load hook smart action](https://docs.forestadmin.com/documentation/reference-guide/actions/create-and-manage-smart-actions/use-a-smart-action-form#prefill-a-form-with-default-values), I think it can help 😉

---

<div class="post-metadata">

**Author:** ![Mayur\_Malaviya](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mayur_malaviya/32/2638_2.png) [@Mayur\_Malaviya](https://community.forestadmin.com/u/Mayur_Malaviya)\
**Post date:** [July 26, 2021, 9:31am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/8 "2021-07-26T09:31:35Z")

</div>

@Guillaume_Cisco I think still you can’t understand my issue. let me describe it.  
If I keep smart action in users collections then I need to choose promocode, which promocode I wants to send, let suppose it provide promocode 1,2,3 then I choose 2. It must send promocode 2 to all users.  
As you mention above link, it helps if I would like to take any number or text input from user then it would be helpful but here, we have promocode collections and I wants to choose from them.

---

<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:** [July 26, 2021, 1:45pm UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/9 "2021-07-26T13:45:50Z")

</div>

@Mayur_Malaviya,

I perfectly understand your problem.  
You need to create a smart action with a smart action form and define a field which will be an enum for your promo codes.  
This way, you will be able to select some users, then select a promo code, and on your server you will be able to send to all your selected users, an email with a promo code.  
Don’t forget to use a field with an `Enum` type + use the load hook to load the expected promo codes.

Cheers,

---

<div class="post-metadata">

**Author:** ![Mayur\_Malaviya](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mayur_malaviya/32/2638_2.png) [@Mayur\_Malaviya](https://community.forestadmin.com/u/Mayur_Malaviya)\
**Post date:** [July 27, 2021, 8:59am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/10 "2021-07-27T08:59:21Z")

</div>

@Guillaume_Cisco Thanks for this nice suggestion. I have tried to implement as you explained.

```javascript
actions: [{
    name: 'Promocode Send',
    type: 'bulk',
    fields: [{
      field: 'promocodes',
      type: 'Enum',
      enums: []
    }],
    hooks: {
      load: async ({ fields, request }) => {
        console.log('>>>>>>>>>>>LOAD HOOKS>>>>>>>>>>>>');
        const promocodesField = fields.find(field => field.field === 'promocodes');
        const promocodesDetails = await promocodes.findAll({ attributes :['id', 'name']});
        console.log(">>>>>>>>>>>>>PROMOCODE DETAILS>>>>>>>>>>>>>>>>.");
        console.log(promocodesDetails);
        promocodesField.enums = promocodesDetails;
        return fields;
      }
    }
  }],

```

I have implemented here. It won’t console even first line.

 ![output](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/7/7b3af3bd165dcd90784fcdfe091a9c13eae56e67.png)

I have tried to refresh whole page, re-run the project and all. When this hook will load.  
Here is output. It seems empty.

 ![promocode action](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/d/dbe6afea6c496dd8d72a89a34cec869c4327da00.png)

Moreover, In the documentation provide sample code. I am confused with first line. What should I write in the **my-own-helper** file?

```javascript
const { getEnumsFromDatabaseForThisRecord } = require('./my-own-helper');
const { getZipCodeFromCity } = require('...');
const { collection } = require('forest-express-sequelize');
const { customers } = require('../models');

collection('customers', {
  actions: [{
    name: 'Send invoice',
    type: 'single',
    fields: [
      {
        field: 'country',
        type: 'Enum',
        enums: []
      },
      {
        field: 'city',
        type: 'String',
        hook: 'onCityChange'
      },
      {
        field: 'zip code',
        type: 'String',
        hook: 'onZipCodeChange'
      },
    ],
    hooks: {
      load: async ({ fields, request }) => {
        const country = fields.find(field => field.field === 'country');
        
        const id = request.body.data.attributes.ids[0];
        const customer = await customers.findByPk(id);

        country.enums = getEnumsFromDatabaseForThisRecord(customer);

        return fields;
      },
      change: {
        onCityChange: async ({ fields, request, changedField }) => {
          const zipCode = fields.find(field => field.field === 'zip code');
          
          const id = request.body.data.attributes.ids[0];
          const customer = await customers.findByPk(id);

          zipCode.value = getZipCodeFromCity(
            customer, 
            changedField.value
          );

          return fields;
        },
        onZipCodeChange: async ({ fields, request, changedField }) => {
          const city = fields.find(field => field.field === 'city');

          const id = request.body.data.attributes.ids[0];
          const customer = await customers.findByPk(id);

          city.value = getCityFromZipCode(
            customer,
            changedField.value
          );

          return fields;
        },
      },
    },
  }],
  fields: [],
  segments: [],
});

```

Please suggest me. Is the way I used perfect or not?

---

<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:** [July 27, 2021, 9:55am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/11 "2021-07-27T09:55:04Z")

</div>

Hello @Mayur_Malaviya,

Which version of `forest-express-sequelize` are you using?  
The code you shew to me is compatible from the v8.

Please let me know your version.

Thanks,

---

<div class="post-metadata">

**Author:** ![Mayur\_Malaviya](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mayur_malaviya/32/2638_2.png) [@Mayur\_Malaviya](https://community.forestadmin.com/u/Mayur_Malaviya)\
**Post date:** [July 27, 2021, 9:58am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/12 "2021-07-27T09:58:22Z")

</div>

@Guillaume_Cisco  
“forest-express-sequelize”: “^7.0.0”

How can I upgrade it.

---

<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:** [July 27, 2021, 10:00am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/13 "2021-07-27T10:00:19Z")

</div>

Alright @Mayur_Malaviya,

That’s why you won’t see any logs.  
Please refer to the documentation for knowing how to [upgrade to V8 with sequelize](https://docs.forestadmin.com/documentation/how-tos/maintain/upgrade-notes-sql-mongodb/upgrade-to-v8).

---

<div class="post-metadata">

**Author:** ![Mayur\_Malaviya](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mayur_malaviya/32/2638_2.png) [@Mayur\_Malaviya](https://community.forestadmin.com/u/Mayur_Malaviya)\
**Post date:** [July 28, 2021, 4:17am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/14 "2021-07-28T04:17:52Z")

</div>

@Guillaume_Cisco I have read the documentation of the ForestAdmin. It seems hooks concept is available in version 7 as well.  
[Click here](https://docs.forestadmin.com/documentation/v/v7-v6-rails/reference-guide/actions/create-and-manage-smart-actions) for that document.

---

<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:** [July 28, 2021, 7:34am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/15 "2021-07-28T07:34:53Z")

</div>

Perfect @Mayur_Malaviya !

Yes, hooks concept is also available in version 7, but the syntax is different.  
You can see the modification in the upgrade note.

I strongly recommend you to use the last version, the 8 one 😃 as it supports **bulk** smart actions! It seems to be the case for you 😉

Let me know if it helps 🚀

---

<div class="post-metadata">

**Author:** ![Mayur\_Malaviya](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mayur_malaviya/32/2638_2.png) [@Mayur\_Malaviya](https://community.forestadmin.com/u/Mayur_Malaviya)\
**Post date:** [July 28, 2021, 7:37am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/16 "2021-07-28T07:37:20Z")

</div>

@Guillaume_Cisco I need to resolve it with version 7 because I have already done lot work and syntax of action and there are lot many changing break. so, I need to find solution with version 7. As I read the document, I think bulk action with hooks is not supported in version 7.

---

<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:** [July 28, 2021, 7:38am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/17 "2021-07-28T07:38:33Z")

</div>

Ok great! @Mayur_Malaviya

It looks like only **single** smart actions are available with hooks concepts in version 7.  
Maybe transform your smart action to a **single** type one?

Cheers,

---

<div class="post-metadata">

**Author:** ![Mayur\_Malaviya](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mayur_malaviya/32/2638_2.png) [@Mayur\_Malaviya](https://community.forestadmin.com/u/Mayur_Malaviya)\
**Post date:** [July 28, 2021, 7:40am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/18 "2021-07-28T07:40:09Z")

</div>

@Guillaume_Cisco Can you suggest any other ways?

---

<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:** [July 28, 2021, 7:47am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/19 "2021-07-28T07:47:12Z")

</div>

@Mayur_Malaviya,

Maybe you could use the `values` concept available [here](https://docs.forestadmin.com/documentation/v/v5/reference-guide/actions/create-and-manage-smart-actions#prefill-a-form-with-default-values), but it is deprecated and I strongly recommend you to upgrade to v8.

Be aware `Values` function is available for **single** type action only.

Let me know if it helps 😉

---

<div class="post-metadata">

**Author:** ![Mayur\_Malaviya](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mayur_malaviya/32/2638_2.png) [@Mayur\_Malaviya](https://community.forestadmin.com/u/Mayur_Malaviya)\
**Post date:** [July 28, 2021, 7:50am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/20 "2021-07-28T07:50:52Z")

</div>

@Guillaume_Cisco  
I agree with you that we should upgrade version but we are near to done the whole code and move to production and during this time I can’t take risk to upgrade the version. If this project is done once, we can do it meanwhile.

Let me check that functionality. I will let you know if it helps me.

Thanks

---

<div class="post-metadata">

**Author:** ![Mayur\_Malaviya](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/mayur_malaviya/32/2638_2.png) [@Mayur\_Malaviya](https://community.forestadmin.com/u/Mayur_Malaviya)\
**Post date:** [August 2, 2021, 6:03am UTC](https://community.forestadmin.com/t/regarding-fetch-new-collection-ids/2984/21 "2021-08-02T06:03:47Z")

</div>

@Guillaume_Cisco This functionality is possible with **single** type action only but my requirements must required **bulk** action type. I resolve that not using this functionality but in another way.

Thanks for your response and provide me all possible ways.
