Array To Map | ARRAY_TO_MAP
Syntax
ARRAY_TO_MAP( [value], [keyPath] )
Parameters
value
The ARRAY of MAP / OBJECT records being converted into a MAP.
keyPath
A path used to select the key for each entry in the resulting map.
The key should probably reference to a value that is unique in each item, otherwise values may not be added to the resulting map.
For more information on the path syntax used by instalink.io see the dedicated documentation on that subject.
A block may also be submitted in place of the key. This block function may be used to calculate the key that will be used for each entry in the resulting map.
Return Value
An MAP containing all the items in VALUE with the value at KEY used as the MAP key.Description
Convert an ARRAY of OBJECT / MAP records into a MAP of those records using a path to get the key for each sub item in the result. This operation can, for example, be used to convert an ARRAY of records into a MAP where the keys in the map are the primary identifier of the record.Examples
# VALUE is [
# ["id" => "abc", "data" => 1],
# ["id" => "def", "data" => 2]
# ]
ARRAY_TO_MAP(VALUE, "id")
# returns [
# "abc" => ["id" => "abc", "data" => 1],
# "def" => ["id" => "def", "data" => 2]
# ]
# VALUE is [
# ["order_number" => "abc", "line_number" => 1],
# ["order_number" => "abc", "line_number" => 2],
# ["order_number" => "def", "line_number" => 1]
# ]
ARRAY_TO_MAP(VALUE, {|line|
TEXT_CONCAT($line.order_number, "-", $line.line_number)
})
# returns [
# "abc-1" => ["order_number" => "abc", "line_number" => 1],
# "abc-2" => ["order_number" => "abc", "line_number" => 2],
# "def-1" => ["order_number" => "def", "line_number" => 1]
# ]