Get selected records within :Load hook

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.

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.

@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 :slight_smile: )

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 :+1:

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

@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 :+1:

got it, thank you for the clarification :pray:

@jeffladiray 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!

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.