# Bug with "Select current page only" + smart action

**URL:** <https://community.forestadmin.com/t/bug-with-select-current-page-only-smart-action/3032>\
**Category:** Help me!\
**Created:** [August 2, 2021, 1:58pm UTC](https://community.forestadmin.com/t/bug-with-select-current-page-only-smart-action/3032 "2021-08-02T13:58:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![arnaudambro](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaudambro/32/1480_2.png) [@arnaudambro](https://community.forestadmin.com/u/arnaudambro)\
**Post date:** [August 2, 2021, 1:58pm UTC](https://community.forestadmin.com/t/bug-with-select-current-page-only-smart-action/3032/1 "2021-08-02T13:58:01Z")

</div>

## Expected behavior

I have a smart segment, with 126 items inside  
I wanted to do a smart action for each of them, I clicked on the checkbox on top of the checkbox column, and I triggered my smart action.  
Then I realised I did the smart action on the current page only, so I did the same stuff on pages 2 then 3 then 4 of my segment

The smart action was about sending a SMS to each user of my segment, and some of them told me “hey ! I received 4 times your SMS !”

Then I checked, and indeed, some of the ids I received with `new RecordsGetter(User).getIdsFromRequest(req);` on pages 2-3-4 were already on page 1.

[EDIT] it’s the actual pagination which is broken

## Actual behavior

Working correctly !

## Failure Logs

Please include any relevant log snippets, if necessary.

## Context

Please provide any relevant information about your setup.

- Package Version: “forest-express-mongoose”: “^7.6.0”,
- Express Version: “express”: “4.17.1”,
- Sequelize Version:
- Database Dialect:
- Database Version:
- Project Name: can say on MP

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [August 2, 2021, 3:56pm UTC](https://community.forestadmin.com/t/bug-with-select-current-page-only-smart-action/3032/2 "2021-08-02T15:56:39Z")

</div>

Hey @arnaudambro!

Thanks for your message 🙌

That’s very not cool, let’s investigate what’s going on here.  
Could you please tell me:

- What is your smart action type (bulk, global or simple)?
- Is this smart action defined on a regular collection or on smart collection?
- You said that some of the ids you received on pages 2-3-4 were already on page 1. So not all of them? Does it look random to you?
- Apparently you have identified an issue with the current pagination, would you mind sharing what you discovered?

Thanks!

PS: Do you know that you can [select all the records](https://docs.forestadmin.com/documentation/reference-guide/views/the-table-view#select-all-records-vs-select-current-page-only) (all pages - not only the current one)?

---

<div class="post-metadata">

**Author:** ![arnaudambro](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaudambro/32/1480_2.png) [@arnaudambro](https://community.forestadmin.com/u/arnaudambro)\
**Post date:** [August 2, 2021, 5:45pm UTC](https://community.forestadmin.com/t/bug-with-select-current-page-only-smart-action/3032/3 "2021-08-02T17:45:41Z")

</div>

Yes, I told my client to select all the records to avoid mistakes, but still

- the smart action is bulk
- it’s defined on a regular collection (I didn’t know we could create a smart collection)
- it looks random, although it’s always the same results
- no idea how it could bug !

For your investigation,

my smart segment is:

```javascript
    {
      name: 'CESTCADEAU5 Sélection',
      where: async () => {
        const users = await User.find({ arrayField: 'CESTCADEAU5' });
        const userIds = users.map((u) => u._id);
        return { _id: { $in: userIds } };
      },
    },

```

my smart action

```javascript
      name: 'Send Test SMS',
      type: 'bulk',
      fields: [
        {
          field: 'text',
          isRequired: true,
          description: 'What do you want to say ?',
          type: 'string',
        },
      ],
    },

```

my smart action route

```javascript
// Send SMS text message
router.post('/actions/send-test-sms', permissionMiddlewareCreator.smartAction(), async (req, res) => {
  try {
    const { text } = req.body.data.attributes.values;
    const userIds = await new RecordsGetter(User).getIdsFromRequest(req);
    const users = await User.find({ _id: userIds });

    for (let user of users) {
      await sendSms(user.phone, text, user._id);
    }

    res.status(200).send({
      success: users.length > 1 ? `SMS sent to ${users.length} users !` : 'SMS sent !',
    });
});

```

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [August 3, 2021, 4:03pm UTC](https://community.forestadmin.com/t/bug-with-select-current-page-only-smart-action/3032/4 "2021-08-03T16:03:18Z")

</div>

@arnaudambro,

Thanks for the elements.  
Unfortunately, I was not able to reproduce this problem.

Could you please share with me:

- a screenshot with the collection current page, and the smart action payload (with the `ids` displayed) → we might see the diff here

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/0/06e92eb3acd696f54e223d2acf18aa002b95487b.png)

- the result on the server side of `userIds = await new RecordsGetter(user).getIdsFromRequest(req);`

Many thanks!

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [September 13, 2021, 12:48pm UTC](https://community.forestadmin.com/t/bug-with-select-current-page-only-smart-action/3032/5 "2021-09-13T12:48:18Z")

</div>

Hello @arnaudambro,

Any news on this subject?

Thanks!

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [November 2, 2021, 10:29am UTC](https://community.forestadmin.com/t/bug-with-select-current-page-only-smart-action/3032/6 "2021-11-02T10:29:16Z")

</div>

Hello @arnaudambro,

Thanks for your message shared in private!

Could you please try to upgrade the agent `forest-express-mongoose` to the latest version and see if the issue persists?

Thanks 🙏

---

<div class="post-metadata">

**Author:** ![arnaudambro](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaudambro/32/1480_2.png) [@arnaudambro](https://community.forestadmin.com/u/arnaudambro)\
**Post date:** [November 2, 2021, 12:12pm UTC](https://community.forestadmin.com/t/bug-with-select-current-page-only-smart-action/3032/7 "2021-11-02T12:12:04Z")

</div>

> [@anon34731316](#):
>
> `forest-express-mongoose`

`"forest-express-mongoose": "^7.9.2"`

still the exact same…

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [November 2, 2021, 1:36pm UTC](https://community.forestadmin.com/t/bug-with-select-current-page-only-smart-action/3032/8 "2021-11-02T13:36:15Z")

</div>

Could you try with the 8.4.3?

---

<div class="post-metadata">

**Author:** ![arnaudambro](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/arnaudambro/32/1480_2.png) [@arnaudambro](https://community.forestadmin.com/u/arnaudambro)\
**Post date:** [November 2, 2021, 3:16pm UTC](https://community.forestadmin.com/t/bug-with-select-current-page-only-smart-action/3032/9 "2021-11-02T15:16:34Z")

</div>

still the same

here are my deps

```javascript
 "dependencies": {
    "@sentry/node": "^5.23.0",
    "aws-sdk": "^2.832.0",
    "bcrypt": "^5.0.0",
    "chalk": "~1.1.3",
    "cookie-parser": "1.4.4",
    "cors": "2.8.5",
    "debug": "~4.0.1",
    "dotenv": "~6.1.0",
    "express": "4.17.1",
    "express-jwt": "^6.1.0",
    "firebase-admin": "^9.4.2",
    "forest-express-mongoose": "^8.4.3",
    "form-data": "^4.0.0",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^6.0.12",
    "morgan": "1.9.1",
    "node-fetch": "^2.6.1",
    "node-schedule": "^1.3.2",
    "npm": "^8.0.0",
    "require-all": "^3.0.0",
    "urijs": "^1.19.6"
  }

```

---

<div class="post-metadata">

**Author:** ![anon34731316](https://avatars.discourse-cdn.com/v4/letter/a/eada6e/32.png) [@anon34731316](https://community.forestadmin.com/u/anon34731316)\
**Post date:** [October 7, 2022, 12:08pm UTC](https://community.forestadmin.com/t/bug-with-select-current-page-only-smart-action/3032/10 "2022-10-07T12:08:59Z")

</div>

Hello @arnaudambro,

I know this ticket is quite old, I don’t know if you still have the issue on your project.  
I’ve never been able to reproduce, but I just came on [another ticket](https://community.forestadmin.com/t/sorting-pagination/806) that might be linked to your issue.

Could you tell me if the collection where you have the problem is ordered by a non-unique field?

Thanks a lot.
