Instalink Scripting Documentation

Dates

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

Encoding

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

Lists

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

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 Without Entry
Map Get
Map Has Key
Map Keys
Merge Maps
Map Pairs
Map With Entry
Map Size
Map Values

Math

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

Other

Lookup

Text

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

Type Conversions

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

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]]]