MAP item inside of another MAP function

How to MAP item inside of MAP function

this may confusing. let me explain farther .

I give an example and maybe this is a problem for others and this formula help to boost your mapping process.

ex.1:i created app variables named pageVars.myList list of object with 2 property ids and names
image

example data/process:
data 1:

[
  {
    id: 1
  },
  {
    id: 2
  },
 {
    id: 3
  },
 {
    id: 4
  }
]

data 2:

[
  {
    id: 1,
    name: "john"
  },
   {
    id: 1,
    name: "james"
  },
  {
    id: 2,
    name: "mark"
  },
  {
    id: 4,
    name: "tom"
  },
]

This result i want

myList[
  {
    id: 1,
    name: ["john", "james"]
  },
   {
    id: 2,
    name: ["james"]
  },
  {
    id: 3,
    name: []
  },
  {
    id: 4,
    name: ["tom"]
  },
]

Now this is my Formula

pageVars.myList

actual formula

MAP(data 1, {id: item.id, names: MAP(SELECT(data 2, item.id==item.id), item.name )})

explanation

MAP(data 1, {id: item.id, names: MAP(SELECT(data 2, (item.id from data 2) == (item.id from data 1)), item.name )})

getting error sorting data 2 using item.id from data 1 inside of map function of data 2

1 Like

You can use aliases:

MAP<outer>(MAP<inner>(items, {id: inner.id, name: inner.name}), outer.name)

2 Likes

Thank you @Mari . It works :smiling_face_with_three_hearts:

1 Like

how does appgyver know where to get the data from just outer and inner???

yes. base on outer or inner

Is there anywhere I can study the logic of these formulas other than the explainer window in the forumal editor? I know they do not have much room there so, you know.

The first MAP() always refers to the outermost list. By default, its item can be referred to with ‘item’. Since subsequent nested MAP() functions all use the same default, to differentiate between them, you should specify an alias - the actual name of the alias does not matter, as long as it’s something different. The examples showcase some cases of using aliases: Map - list
Note that you can also edit the examples inside the formula editor and get immediate feedback.

What do you mean by “outermost” list?

cannot get my head around it without understanding the logic behind how the formulas operate. in Java its this simple

users.add(user)

that adds a user object to the end of an array of objects