# Get selected records within :Load hook

**URL:** <https://community.forestadmin.com/t/get-selected-records-within-load-hook/3895>\
**Category:** Help me!\
**Created:** [December 13, 2021, 7:02am UTC](https://community.forestadmin.com/t/get-selected-records-within-load-hook/3895 "2021-12-13T07:02:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![huss](https://avatars.discourse-cdn.com/v4/letter/h/dfb087/32.png) [@huss](https://community.forestadmin.com/u/huss)\
**Post date:** [December 13, 2021, 7:02am UTC](https://community.forestadmin.com/t/get-selected-records-within-load-hook/3895/1 "2021-12-13T07:02:24Z")

</div>

hello,

i am trying to fetch the ids of the selected records in a smart action within the :Load hook, and there is a way shown in your documentation to do that but i believe it is deprecated since it raises an error whenever i try to do it.

the method mentioned in the documentation is:  
`ForestLiana::ResourcesGetter.get_ids_from_request(context[:params]);`

but it raises an argument error:  
`ArgumentError - wrong number of arguments (given 1, expected 2):`

note that the method mentioned above was also used for the same purpose in the model’s controller but it also stopped working a while back and now i must pass the `params` and the `forest_user` along with it.

but in the :Load hook there is no such forest\_user in the context so i was wondering what i could do to fetch the selected records ids within the :Load hook.

---

<div class="post-metadata">

**Author:** ![huss](https://avatars.discourse-cdn.com/v4/letter/h/dfb087/32.png) [@huss](https://community.forestadmin.com/u/huss)\
**Post date:** [December 13, 2021, 7:03am UTC](https://community.forestadmin.com/t/get-selected-records-within-load-hook/3895/2 "2021-12-13T07:03:55Z")

</div>

i went through the context data and found that i could fetch the ids manually like this:  
`context[:params][:data][:attributes][:ids].count`

but i am afraid that you guys might change the structure of the sent data within the context and this would stop working, so i was wondering if there is a better way to do this.

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [December 13, 2021, 9:12am UTC](https://community.forestadmin.com/t/get-selected-records-within-load-hook/3895/3 "2021-12-13T09:12:54Z")

</div>

@huss,

This would be a breaking change on our end, so this is not expected to change before a major (8.x.x) release (So this should work for a while 🙂 )

Just to be safe, you could use the `getIdsFromRequest`, that will handle the complete conversion between the selected items & a list of `ids` available on your agent.

I’m marking this thread as resolved in favor of all the other one opened, feel free to ask more questions there 👍

---

<div class="post-metadata">

**Author:** ![huss](https://avatars.discourse-cdn.com/v4/letter/h/dfb087/32.png) [@huss](https://community.forestadmin.com/u/huss)\
**Post date:** [December 13, 2021, 9:44am UTC](https://community.forestadmin.com/t/get-selected-records-within-load-hook/3895/4 "2021-12-13T09:44:39Z")

</div>

how exactly do i use this method within the `:Load` hook? could you give me an example

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [December 13, 2021, 10:25am UTC](https://community.forestadmin.com/t/get-selected-records-within-load-hook/3895/5 "2021-12-13T10:25:41Z")

</div>

@huss,

Seems like you were right in your initial message. The V7 introduced a breaking change on this API, forcing `get_ids_from_request` to have access to `forest_user`, but the smart action hook context does not provide this info. I’m opening a ticket on our end.

In the meantime, I can guarantee that `ids` will not change, so it is safe to assume that `context[:params][:data][:attributes][:ids].count` will still work in any case 👍

---

<div class="post-metadata">

**Author:** ![huss](https://avatars.discourse-cdn.com/v4/letter/h/dfb087/32.png) [@huss](https://community.forestadmin.com/u/huss)\
**Post date:** [December 13, 2021, 10:34am UTC](https://community.forestadmin.com/t/get-selected-records-within-load-hook/3895/6 "2021-12-13T10:34:37Z")

</div>

got it, thank you for the clarification 🙏

---

<div class="post-metadata">

**Author:** ![nico\_lrx](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nico_lrx/32/708_2.png) [@nico\_lrx](https://community.forestadmin.com/u/nico_lrx)\
**Post date:** [November 29, 2022, 8:21am UTC](https://community.forestadmin.com/t/get-selected-records-within-load-hook/3895/7 "2022-11-29T08:21:19Z")

</div>

@anon39848301 any news on this? I have the same error using forest\_liana 7.7.1. My fix was to retrieve the ID of the object with this: `params[:data][:attributes][:ids]`

Thank you!

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [November 29, 2022, 11:03am UTC](https://community.forestadmin.com/t/get-selected-records-within-load-hook/3895/8 "2022-11-29T11:03:58Z")

</div>

It should have been fixed (For the user part of the issue) in the \>=7.4.2 version of forest-rails. forest user is now provided in the smart action hook, so it should be accessible to be used in the `get_ids_from_request` helper.
