Calling custom actions within actions

I am using trying to figure out how to call another action within actions. Let me give you an example:

Suppose I am trying to fetch categories from my API. There can be subcategories on multiple levels. after loading the root category and show them in quick access to the user. How I can capture the selected value (which value(category id) is dynamically generated) and then call another action or redirect to the same action?

I have to call (transition) to action manually after getting each input from the user. In first action i am loading main categories, then after getting user response, I am calling the same action again to load subcategory. As mentioned earlier subcategory level is dynamic. What is the right approach to do it.

Hi @saimoomsafayet,

You can use Memory to store the first categoryId and then fetch the subcategories in another action:

(approximative code alert)

1. Get categories

function async getCategories() {
  const {data} = axios.get('/categories')
  session.categories = data

return getCategories()

2. Display the categories

Create a content element and display the categories with the help of templating.

3. Get the user input and store it in Memory:

4. Get the subcategories based on the user input

function async getSubCategories(categoryId) {
  const {data} = axios.get(`/categories/${categoryId}/subcategories/`)
  session.subcategories = data

return getSubCategories(session.categoryId)

5. Continue with your custom logic

Hope this helps!

1 Like