Error applying get with embeded map

:bullseye: What is your goal?

Learn and become an expert

:thinking: What is the problem?

My result on the follwoing scenario should be just :
Price of sport socks: 9
but it is :
Price of sport socks 1

:test_tube: What have you tried so far?

I followed the tutorial "Make intermediate 2-3"on make web page

:link: Create public scenario page

Hey there,

you are missing a semicolon inside the get() function.

{{get(map(1.shopping_basket.items; "item_price"; "item_name"; "Sports socks"); 1)}}

Hello Stoyan_Vatov, thanks for your anser but I think is not tha solution. I added the semicolon an te result is:

and it should be:

In your answer you are using:

1.shopping_basket**.**items; (using point betweeen basket and items)

I tried to apply the same but I can’t in mine. My code looks differente but I dont know why I cant put it like you showed me:
{{get(map(1.shopping_basket.item**s; “**item_price”; “item_name”; “Sport socks”); 1)}}

You can copy my code and replace yours with it and it should work.

Most likely you have an empty space somewhere causing a mismatch in one of the arguments it’s trying to filter by.

I did, but when copied it becomes again:

{{get(map(1.shopping_basket: items[ ]; “item_price”; “item_name”; “Sports socks”); 1)}}

Please. I dont want to get stuck. I need you guidance friends. be mercyfull with this debutant :grin:

Welcome to the Make community!

Based on the provided blueprint export, you have three issues.

Here’s what you did:

  1. The order of parameters is incorrect. Swap item_name with item_price
  2. You mistyped Sport socks. It should be Sports socks.
  3. A map function returns an array. If you want a single value from the array, you need to use the first function as well.

Here’s the corrected version:

A more in-depth explanation of the map/first functions is provided below.


Combining Map & Get (or First) functions to get Values from Arrays

The built-in functions map, get, first (or `last) allows you to access values within an array containing collections.

First, use the map function on an array, which returns another array of filtered values —
map(array; key; [key for filtering]; [csv-values for filtering])

Then, the built-in function get (or first/last) to get a specific, single item from the resulting array —
get(array; path)

You will get something that looks like these —

{{ get(map(array; "value"; "name"; "content-type"); 1) }}
{{ first(map(array; "value"; "name"; "content-type")) }}

Map Function Parameters: Step-by-Step

To easily remember how to use each of the parameters of the map function, think of it this way:

  1. From this array (of collections),
  2. I want to get all the the values for the property/key named _______,
  3. Where another property/key _______
  4. has the exact case-sensitive value _______

Example

1. From this array (of collections) user_column_data

2. I want to get all the the values for the property/key named string_value

3. Where another property/key column_id

4. has the exact case-sensitive value EMAIL

5. Output

e.g.:

{{ first(map(5.user_column_data; "string_value"; "column_id"; "EMAIL")) }}

:high_voltage: Make Input Markup: Copy-paste the above into the field, including start/end curly brackets for it to import as intended :warning:

Using Join Function to Transform an Array into a Single Text Variable

You can also combine map with join to join the values into a single text string —
{{ join(map( ... ); delimiter) }}

e.g.:

{{ join(map(array); ", ") }}

For more information, the documentation for the above functions can be found in the Help Centre and the “Mapping with Arrays” link below. You should also complete the tutorials in the Make Academy, especially Using get() and map() functions as this is the most important knowledge you need to understand so that you can successfully apply it when building scenarios using Make.

Links & Guides

Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I’d also recommend going through the Make Academy if you haven’t yet!

Learn Make

How-Tos

Useful to Know

My Custom App — Absolutely Free!

Save development time and operation credits with these utility modules: Chunk Text; Chunk Array; Chunk Words; Multiple Find & Replace; Collection to Array/String List; Execute JavaScript; Estimate Tokens; Calculate Difference Between Two Dates; Get Next Business Day (with holidays); List Upcoming Dates of Day of Week; and more!

If you have a follow-up question, please start a new thread. Thanks!

— @samliew