Afterfetch, beforefetch life cycle methods are not working

i want to display collection list on admin panel based on custom logic. like based on logged in user, i want to display specific list for that i haver tried with
Callbacks on fetch: beforeFetch, afterFetch.
Callbacks on fetchAll: beforeFetchAll, afterFetchAll. but those callbacks are not triggerd.

and also i have tried with beforefind and afterfind but those are triggered when i am hitting http get request but admin panel actions are not working.

could you please provide fetch related lifecycle methods in 3.6.8 version.

System Information
  • Strapi Version: 3.6.8
  • Operating System:
  • Database: mysql
  • Node Version: 12.22
  • NPM Version:
  • Yarn Version:

Is this in a plugin that you are trying to add these? Can you be a bit more specific?

No I am not trying into the plugin.

I have created product collection content type and it contains vendorid attribute, so based on logged in user need to display list products based on vendorid attribute.

I have return the logic like based based on logged in user I have fetch vendorid from vendor collection type and based on vendorid I want to fetch the products for vendor specific ones.

I am trying into the product.js which is into the model folder of collection type

Hello @ravi_kumar from what I’ve read, it looks like you’re trying to achieve what is essentially, RBAC Conditionals. Have you considered that to be a possible route to meet your requirements?

Is this for the end-user (aka REST/GraphQL) or Admin that you are trying to make modifications.

also the syntax you are using is a bit outdated, beforeFetch and afterFetch aren’t lifecycle functions. I think you mean beforeFind and afterFind based on our documentation: Backend customization - Strapi Developer Documentation

here end user is admin, could you please provide which life cycle functions need to use instead of beforefetch and afterfetch in latest version.

i have tried with beforefind and afterfind but those are triggered via aka Rest. but i am using end user is a admin.

through admin beforefind and afterfind functions are not triggered.

We don’t have the ability to use lifecycles for Admin panel users, there are specific functions designed for those here: Configurations - Strapi Developer Documentation but they only apply to SSO and not regular User + Pass authentication.

Is it possible to change the result of a collectionlist before it is displayed in the admin UI, e.g. to filter out certain records before they are displayed ? Is there a lifecycle hook that could be used for this ?

There is a method but it’s only for enterprise licenses (any level) but is still considered unstable and experimental for now.

It’s called conditionals: Configurations - Strapi Developer Documentation