Instalink Scripting Documentation

Dates

Adjust by Timezone
Current date
Current timestamp
Day of Month
Day of Week (number)
Day of Week (text)
Month (number)
Month (text)
Months ago
Truncate date to day
Truncate date to hour
Truncate date to minute
Truncate date to month
Truncate date to year
Year
Years ago

Encoding

Base 64 Decode
Base 64 Encode
CSV Decode
CSV Encode
JSON Decode
JSON Encode
URI Decode
URI Encode
X12 Decode
X12 Encode
XML Decode

Lists

Aggregate Array
Aggregate Array By Group
All But First Item in List
All But Last Item in List
Array To Map
Combine Two Arrays Without Duplicates
Count of Items in List
Each Item in List as List
Extract Part of Array
Filter List by Matches
Filter List by Non-Matches
Filter List: Unique
Filter List: Unique By Key
First Item in List
Flatten List
Flatten List Recursively
Get Common Items In Arrays
Get Item In List At Index
Group Array By Value
Join List Into Text
Last Item in List
List Append
List Contains Value
List Get Index
List Sort By Key
Pluck Values from List Items
Random Item in List
Randomize List
Remove Index From List
Removes Items From Array In Other Arrays
Reverse List
Set Item In List At Index
Sort List
Transpose List of Lists

Logic

And
Equal to
Exists
Greater Than
Greater Than or Equal
Less Than
Less Than or Equal
Match
Not equal to
Or
Xor

Maps

Map Get
Map Has Key
Map Keys
Map Pairs
Map Size
Map Values
Map With Entry
Map Without Entry
Merge Maps

Math

Absolute value
Add
Cube Root
Divide
Divide (whole number)
Exponent
Multiply
Negate
Random Number
Random Whole Number
Remainder
Round down
Round number
Round towards zero
Round up
Square Root
Subtract

Other

Lookup

Presets

ISO Country
ISO Subdivision

Text

Append Text
Capitalize words
Concatenate Text
Create Hash
Create HMAC Signature
Extract HTML Attribute
Extract HTML Text
Extract Inner HTML
Extract Outer HTML
Left trim text
Lower case
Prepend Text
Replace Text
Right trim text
Search Text
Split Text Into Lines
Split Text Into Words
Sub Text
Text Contains
Text length
Text split
Trim text
Upper case

Type Conversions

As Is
Boolean
Date
Date to String
List
Map
Number
Number to Fixed Decimal String
Text
Timestamp
Whole Number

Aggregate Array By Group | ARRAY_GROUP_AGGREGATE

Syntax

ARRAY_GROUP_AGGREGATE( [value], [key], [aggregation] )

Parameters

value
The ARRAY being aggregated. It should be an ARRAY of MAP / OBJECT records.

key
A single path or an array of paths used to select the value in each entry for grouping. If the path is an array, the items will be grouped by all the unique, ordered combinations of the values. For more information on the path syntax used by instalink.io see the dedicated documentation on that subject.

aggregation
A MAP that defines how the VALUE is to be aggregated. Each key in the MAP should be a path into the entries in the VALUE array. Each value in the map must be an aggregation operator. The valid operators are as follows:

Return Value

An array of MAP / OBJECT with the results of the aggregation performed on each grouped ARRAY of VALUE.

Description

Reduce an ARRAY of OBJECT / MAP records into an ARRAY of OBJECT according to a grouping key and a provided aggregation operation. This function is equivalent to calling ARRAY_GROUP_BY on an array and then calling ARRAY_AGGREGATE on each ARRAY group.

Examples

# VALUE is [
#   ["a" => 1, "b" => 2, "c" => "a"],
#   ["a" => 3, "b" => 4, "c" => "b"],
#   ["a" => 5, "b" => 6, "c" => "a"]
# ]
ARRAY_GROUP_AGGREGATE(VALUE, "c", ["a" => "sum", "b" => "average"])
# returns [["a" => 6, "b" => 4], ["a" => 3, "b" => 4]]
# VALUE is [
#   ["a" => 1, "b" => 2, "c" => "a"],
#   ["a" => 3, "b" => 4, "c" => "b"],
#   ["a" => 5, "b" => 6, "c" => "a"]
# ]
ARRAY_GROUP_AGGREGATE(VALUE, "c", ["a" => "first", "b" => "last"])
# returns [["a" => 1, "b" => 6], ["a" => 3, "b" => 4]]
# VALUE is [
#   ["a" => 1, "b" => 2, "c" => "a"],
#   ["a" => 3, "b" => 4, "c" => "b"],
#   ["a" => 5, "b" => 6, "c" => "a"]
# ]
ARRAY_GROUP_AGGREGATE(VALUE, "c", ["a" => "max", "b" => "min"])
# returns [["a" => 5, "b" => 2], ["a" => 3, "b" => 4]]
# VALUE is [
#   ["a" => 1, "b" => 2, "c" => "a"],
#   ["a" => 3, "b" => 4, "c" => "b"],
#   ["a" => 5, "b" => 6, "c" => "a"]
# ]
ARRAY_GROUP_AGGREGATE(VALUE, "c", ["a" => "push"])
# returns [["a" => [1, 5]], ["a" => [3]]
# VALUE is [
#   ["a" => ["b" => 1], "c" => "a"],
#   ["a" => ["b" => 4], "c" => "b"],
#   ["a" => ["b" => 10], "c" => "a"]
# ]
ARRAY_GROUP_AGGREGATE(VALUE, "c", ["a.b" => "average"])
# returns [["a" => ["b" => 5.5]], ["a" => ["b" => 4]]]