Utility functions
Utility functions convert values between data types and work with grouped results. Use them to cast a value to a number, supply a fallback value, or read a grouping property. Before you start, review the NetScript language reference for formula syntax.
to_string(INPUT)
Use the to_string function to convert a value to a string, such as a number to join with text. The input cannot be a time range.
Function
to_string(INPUT)Data type – string
Example
to_string(5)Result
5to_int(INPUT)
Use the to_int function to convert a number, string, boolean, or timestamp to an integer.
Function
to_int(INPUT)Data type – number
Example
to_int(10.1)
to_int('10')Result
10
10to_boolean(INPUT)
Use the to_boolean function to convert a number, string, or boolean to a boolean.
Function
to_boolean(INPUT)Data type – boolean
Example
to_boolean('true')Result
trueto_float(INPUT)
Use the to_float function to convert a number, string, boolean, or timestamp to a decimal number.
Function
to_float(INPUT)Data type – number
Example
to_float('10.5')Result
10.5to_timestamp(INPUT)
Use the to_timestamp function to convert a number, string, date, or timestamp to a timestamp.
Function
to_timestamp(INPUT)Data type – timestamp
Example
to_timestamp('2024-01-01 08:00:00')Result
2024-01-01 08:00:00coalesce(INPUT_1, INPUT_2, ...)
Use the coalesce function to return the first non-null value from one or more arguments. Use it to supply a fallback value for a missing property. Every argument must have the same data type as the first argument.
Function
coalesce(INPUT_1, INPUT_2, ...)Data type – input type
Example
coalesce(Orders.Discount, 0)Result
The discount for each order, or 0 when the discount is nullgetdim(INPUT, PROPERTY)
Use the getdim function to return the value of a grouping property from an aggregated result. Use the value to filter or sort by that property. The property must already be in the by clause of the input.
Function
getdim(INPUT, PROPERTY)Data type – property type
Example
x = Orders | count by (Orders.Clerk, Orders.Status);
getdim(x, Orders.Status)Result
The status value for each clerk and status groupgetmeasure(INPUT, INDEX)
Use the getmeasure function to select one value from an expression that returns several values, such as [Orders | count, Orders.Amount | sum]. Enter the index as a whole number, starting at 0. The subscript form INPUT[INDEX] works the same way.
Function
getmeasure(INPUT, INDEX)Data type – type of the selected value
Example
m = [Orders | count, Orders.Amount | sum];
getmeasure(m, 1)Result
The total amount of ordersflatten(INPUT_1, INPUT_2, ...)
Use the flatten function to merge several values and lists into one list that shows every value side by side. Enter each argument as a single value or as a list in square brackets. For example, flatten([a, b], [c, d]) returns the same result as [a, b, c, d].
Function
flatten(INPUT_1, INPUT_2, ...)Data type – list
Example
revenue = Orders.Amount | sum;
cost = Orders.Cost | sum;
flatten([revenue, cost], Orders | count)Result
The total amount, the total cost, and the number of orders, side by side