Generic Objects in Expression Language: Difference between revisions
(→String) |
|||
(93 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Array == | == Array == | ||
See introduction to [[QPR_ProcessAnalyzer_Expressions#Arrays|arrays]]. Following list contains all array related functions. | |||
{| class="wikitable" | {| class="wikitable" | ||
Line 109: | Line 27: | ||
||Concat (Array) | ||Concat (Array) | ||
|| | || | ||
Hierarchical object | |||
|| | || | ||
Concatenate multiple arrays together into one. Returns a single array which contains all the arrays given as parameter concatenated together in the same order they were given. If a parameter is not an array, it will be converted into an array having only the given element. | Concatenate multiple arrays together into one. Returns a single array which contains all the arrays given as parameter concatenated together in the same order they were given. If a parameter is not an array, it will be converted into an array having only the given element. | ||
Line 121: | Line 39: | ||
||ConcatTop (Hierarchical object) | ||ConcatTop (Hierarchical object) | ||
|| | || | ||
Hierarchical object | |||
|| | || | ||
Concatenate the topmost arrays in a given hierarchical object. Returns a new hierarchical object with the contents of the topmost level concatenated and removed. | Concatenate the topmost arrays in a given hierarchical object. Returns a new hierarchical object with the contents of the topmost level concatenated and removed. | ||
Line 136: | Line 54: | ||
||CountTop (Integer) | ||CountTop (Integer) | ||
|| | || | ||
Hierarchical object | |||
|| | || | ||
Get the number of elements in the topmost level array of a given array or hierarchical object. If the parameter is not an array, zero is returned. | Get the number of elements in the topmost level array of a given array or hierarchical object. If the parameter is not an array, zero is returned. | ||
Line 150: | Line 68: | ||
CountTop(0) | CountTop(0) | ||
Returns: 0 | Returns: 0 | ||
</pre> | |||
|- | |||
||Distinct | |||
|| | |||
Array or hierarchical object | |||
|| | |||
Modify given array by filtering out all duplicate values leaving only distinct values in the input array into the result. If given a hierarchical object, applies the function at the level that is one level up from the leaf level. | |||
Examples: | |||
<pre> | |||
Distinct([1]) | |||
Returns: [1] | |||
Distinct([1, 1]) | |||
Returns: [1] | |||
Distinct([1, 1, 2, 2]) | |||
Returns: [1, 2] | |||
Distinct([1, 1, 2, 2, "a", DateTime(2017), DateTime(2017), "b", DateTime(2016), "a"]) | |||
Returns: [1, 2, "a", DateTime(2017), "b", DateTime(2016)] | |||
</pre> | |||
|- | |||
||Except | |||
|| | |||
* First array | |||
* Second array | |||
* ... | |||
|| | |||
Creates an substract given items from an array. Returns a single array which contains all the elements that were in the first array that were not in any of the subsequent arrays. If a parameter is not an array, it will be converted into an array having only the given element. | |||
Examples: | |||
<pre> | |||
Except([1, 2, "a", DateTime(2017), 5, "b", 6], ["a", 2, 3, DateTime(2017), 5], [DateTime(2017), "a", 2, 6]) | |||
Returns: [1, "b"] | |||
</pre> | |||
|- | |||
||First (Object) | |||
||Array | |||
|| | |||
Gets the first item in the array. If array has no items, returns ''_empty''. | |||
Examples: | |||
<pre> | |||
First([1,2,3,4]) returns 1. | |||
First([]) returns _empty. | |||
</pre> | </pre> | ||
|- | |- | ||
Line 183: | Line 148: | ||
||In (Boolean) | ||In (Boolean) | ||
|| | || | ||
Array where to search the object | |||
|| | || | ||
Checks whether the current context object exists in given array, and returns either ''true'' or ''false''. Note that the searched object is not given as a parameter, but it's the context object for the function. Examples: | |||
Examples: | |||
<pre> | <pre> | ||
1.In([1,2,3]) | 1.In([1,2,3]) | ||
Line 202: | Line 165: | ||
</pre> | </pre> | ||
|- | |- | ||
|| | ||Intersect | ||
|| | |||
* First array | |||
* Second array | |||
* ... | |||
|| | |||
Creates an intersection of multiple arrays. Returns a single array which contains an intersection of all the items in all the arrays given as parameter. If a parameter is not an array, it will be converted into an array having only the given element. | |||
Examples: | |||
<pre> | |||
Intersect([1, 2, "a", DateTime(2017), 5], ["a", 2, 3, DateTime(2017), 5], [DateTime(2017), "a", 2]) | |||
Returns: [2, "a", DateTime(2017)] | |||
</pre> | |||
|- | |||
||IndexOf (Integer) | |||
|| | || | ||
# | # array | ||
# | # item (Object) | ||
# | # start from (Integer) | ||
|| | || | ||
Gets the index of the first occurrence of the item in the array. If the item is not found, -1 is returned. | |||
Parameters: | |||
# '''array''': Array where to search the item. | |||
# '''item''': Object to search in the array. | |||
# '''start from''' (optional): Index in the array to start the search from. | |||
Examples: | Examples: | ||
<pre> | <pre> | ||
[[1, | IndexOf(["the", "fox", "jumps", "over", "the", "dog"], "the") returns 0. | ||
IndexOf(["the", "fox", "jumps", "over", "the", "dog"], "the", 1) returns 4. | |||
IndexOf(["the", "fox", "jumps", "over", "the", "dog"], "the", 5) returns -1. | |||
IndexOf(["the", "fox", "jumps", "over", "the", "dog"], "a") returns -1. | |||
</pre> | |||
|- | |||
||IndexOfSubArray (Integer*) | |||
|| | |||
# Sub-array to search | |||
# Main-array from where to search | |||
|| | |||
Returns indexes of the given sub-array (1. parameter) within the given main-array (2. parameter). The function returns starting indexes of all the occurrences of given sub-array within given main-array. | |||
If only the first parameter is given, the array in the current context object is used as the main-array. | |||
Examples: | |||
<pre> | |||
IndexOfSubArray([4], [1,2,3,4,1,2,5]) | |||
Return: 3 | |||
IndexOfSubArray([1,2], [1,2,3,4,1,2,5]) | IndexOfSubArray([1,2], [1,2,3,4,1,2,5]) | ||
Return: [0, 4] | Return: [0, 4] | ||
IndexOfSubArray([1,2,4], [1,2,3,4,1,2,5]) | |||
Returns: [] | Returns: [] | ||
[[1,2,3,4,1,2,5 | [[1,2,3,4,1,2,5]].IndexOfSubArray([1,2]) | ||
Return: [0, 4] | |||
] | |||
</pre> | </pre> | ||
|- | |- | ||
||IsArray (Boolean) | ||IsArray (Boolean) | ||
|| | || | ||
Object to check | |||
|| | || | ||
Tests whether given object is an array or hierarchical object. Returns ''true'' if it is. | Tests whether given object is an array or hierarchical object. Returns ''true'' if it is. | ||
Line 238: | Line 235: | ||
</pre> | </pre> | ||
|- | |- | ||
|| | ||Last (Object) | ||
||Array | |||
|| | |||
Gets the last item in the array. If array has no items, returns ''_empty''. | |||
Examples: | |||
<pre> | |||
Last([1,2,3,4]) returns 4. | |||
Last([]) returns _empty. | |||
</pre> | |||
|- | |||
||LastIndexOf (Integer) | |||
|| | |||
# array | |||
# item (Object) | |||
# start from (Integer) | |||
|| | |||
Gets the index of the last occurrence of the item in the array. If the item is not found, -1 is returned. | |||
Parameters: | |||
# '''array''': Array where to search the item. | |||
# '''item''': Object to search in the array. | |||
# '''start from''' (optional): Index in the array to start the search from. | |||
Examples: | |||
<pre> | |||
LastIndexOf(["the", "fox", "jumps", "over", "the", "dog"], "the") returns 4. | |||
LastIndexOf(["the", "fox", "jumps", "over", "the", "dog"], "the", 3) returns 0. | |||
LastIndexOf(["the", "fox", "jumps", "over", "the", "dog"], "a") returns -1. | |||
</pre> | |||
|- | |||
||Reverse (Array) | |||
||Array to reverse | |||
||Reverses an array, i.e. returns a new array, where items are in the inverse order comparing to the original array. | |||
Example: | |||
<pre> | |||
Reverse([1, 2, 3]) | |||
Returns [3, 2, 1] | |||
</pre> | |||
|- | |||
||Shuffle (Array) | |||
|| | || | ||
Array to be shuffled | Array to be shuffled | ||
Line 267: | Line 305: | ||
StringJoin(", ", [[1,2], [3,4]]) | StringJoin(", ", [[1,2], [3,4]]) | ||
Returns: ["1, 2", "3, 4"] | Returns: ["1, 2", "3, 4"] | ||
</pre> | |||
|- | |||
||Union | |||
|| | |||
* First array | |||
* Second array | |||
* ... | |||
|| | |||
Creates an union of multiple arrays. Returns a single array which contains an union of all the items in all the arrays given as parameter. If a parameter is not an array, it will be converted into an array having only the given element. | |||
Examples: | |||
<pre> | |||
Union([1, 2, "a", DateTime(2017), 5], ["a", 2, 3, DateTime(2017), 5], [DateTime(2017), "a", 2, "b"]) | |||
Returns: [1, 2, "a", DateTime(2017), 5, 3, "b"] | |||
</pre> | </pre> | ||
|- | |- | ||
||Zip (Array) | ||Zip (Array) | ||
|| | || | ||
Arrays to be combined | |||
|| | || | ||
Combines multiple arrays into a single array. All the input arrays must be of the same length. Returns an array where the number of elements equal to the number of elements in each of the input arrays. All elements in the Nth position of the array are the concatenated values of Nth elements of each of the input arrays. | Combines multiple arrays into a single array. All the input arrays must be of the same length. Returns an array where the number of elements equal to the number of elements in each of the input arrays. All elements in the Nth position of the array are the concatenated values of Nth elements of each of the input arrays. | ||
Line 298: | Line 350: | ||
== DateTime == | == DateTime == | ||
DateTime represents a timestamp. | DateTime represents a precise timestamp. | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 305: | Line 357: | ||
|- | |- | ||
||Day (Integer) | ||Day (Integer) | ||
||The day of the calendar month | ||The day of the calendar month. Number between 1 and 31. Based on QPR ProcessAnalyzer server local time. | ||
|- | |- | ||
||Hour (Integer) | ||Hour (Integer) | ||
||The hour component of the date | ||The hour component of the date. Number between 0 and 23. Based on QPR ProcessAnalyzer server local time. | ||
|- | |- | ||
||Millisecond (Integer) | ||Millisecond (Integer) | ||
||The millisecond component of the date | ||The millisecond component of the date. Number between 0 and 999. Based on QPR ProcessAnalyzer server local time. | ||
|- | |- | ||
||Minute (Integer) | ||Minute (Integer) | ||
||The minute component of the date | ||The minute component of the date. Number between 0 and 59. Based on QPR ProcessAnalyzer server local time. | ||
|- | |- | ||
||Month (Integer) | ||Month (Integer) | ||
||The calendar month component of the date | ||The calendar month component of the date. Number between 1 and 12. Based on QPR ProcessAnalyzer server local time. | ||
|- | |- | ||
||Second (Integer) | ||Second (Integer) | ||
||The second component of the date | ||The second component of the date. Number between 0 and 59. Based on QPR ProcessAnalyzer server local time. | ||
|- | |- | ||
||Ticks (Integer) | ||Ticks (Integer) | ||
||Number of ticks | ||Number of ticks in the date. The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 (0:00:00 UTC on January 1, 0001, in the Gregorian calendar). A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second. | ||
|- | |||
||UnixMilliseconds (Integer) | |||
||Returns the time as Unix compatible milliseconds (i.e., milliseconds from the first of January 1970 midnight UTC). | |||
|- | |||
||WeekOfYear (Integer) | |||
||Week number of the date (according to the ISO standard). Number between 1 and 53. | |||
|- | |- | ||
||Year (Integer) | ||Year (Integer) | ||
||The year component of the date | ||The year component of the date. Number between 1 and 9999. Based on QPR ProcessAnalyzer server local time. | ||
|} | |} | ||
Line 336: | Line 394: | ||
|| Round (DateTime) | || Round (DateTime) | ||
|| | || | ||
* | * Timespan or Integer | ||
|| | || | ||
Rounds given date time by given | Rounds given date time by given Timespan or given number of seconds. | ||
Example: | Example: | ||
<pre> | <pre> | ||
Round to the nearest hour: | Round to the nearest hour: | ||
Round(DateTime(2017, 1, 1, 14, 48), | Round(DateTime(2017, 1, 1, 14, 48), Timespan(0, 1)) | ||
DateTime(2017, 1, 2, 3, 4, 5).Round(10) | DateTime(2017, 1, 2, 3, 4, 5).Round(10) | ||
Returns: DateTime(2017, 1, 2, 3, 4, 10) | Returns: DateTime(2017, 1, 2, 3, 4, 10) | ||
DateTime(2017, 1, 2, 3, 4, 5).Round( | DateTime(2017, 1, 2, 3, 4, 5).Round(Timespan(1)) | ||
Returns: DateTime(2017, 1, 2) | Returns: DateTime(2017, 1, 2) | ||
</pre> | </pre> | ||
Line 392: | Line 450: | ||
# Millisecond (>= 0) (Integer) | # Millisecond (>= 0) (Integer) | ||
|| | || | ||
Creates a new [[ | Creates a new [[QPR_ProcessAnalyzer_Objects_in_Expression_Language#DateTime|DateTime]] object. Only the first (year) parameter is mandatory. | ||
Examples: | Examples: | ||
Line 408: | Line 466: | ||
||DateTimeFromTicks | ||DateTimeFromTicks | ||
|| | || | ||
Number of ticks (Integer) | |||
|| | || | ||
Creates a new [[ | Creates a new [[QPR_ProcessAnalyzer_Objects_in_Expression_Language#DateTime|DateTime]] object from an integer representing ticks. A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second. | ||
Examples: | Examples: | ||
Line 417: | Line 475: | ||
Returns: A date time object for 6th May 2018 at 13:34:56.123. | Returns: A date time object for 6th May 2018 at 13:34:56.123. | ||
</pre> | </pre> | ||
|- | |- | ||
|| | ||ParseDateTime | ||
|| | || | ||
# String to convert | |||
# Date format (String) | |||
|| | || | ||
Converts the given string to a DateTime using the provided date format. If the parsing fails, an exception is thrown. | |||
The second parameter defines the date format used for conversion. More information: https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings. | |||
Examples: | Examples: | ||
<pre> | <pre> | ||
ParseDateTime("01.01.2020", "dd.MM.yyyy") | |||
Returns | Returns 01.01.2020 as datetime. | ||
ParseDateTime("2020/01/01", "dd.MM.yyyy") | |||
Throws an exception. | Throws an exception. | ||
</pre> | </pre> | ||
| | |} | ||
The following properties can be used to initialize DateTime objects: | |||
{| class="wikitable" | |||
!'''Property''' | |||
! '''Description''' | |||
|- | |- | ||
|| | ||Now (DateTime) | ||
|| | ||[[QPR_ProcessAnalyzer_Objects_in_Expression_Language#DateTime|DateTime]] object representing the current date and time. | ||
|- | |- | ||
|} | |} | ||
== String == | == String == | ||
Line 609: | Line 553: | ||
"test".Contains("st") | "test".Contains("st") | ||
Returns: true | Returns: true | ||
</pre> | |||
|- | |||
||Base64Decode | |||
|| | |||
* base64 string | |||
|| | |||
Decodes a base64 string into a normal string by interpreting the data as UTF8. Encoding is done by converting the base64 string into bytes and converting those bytes into string by interpreting them as UTF8 encoded data. Returns an empty string for an empty input base64 string. | |||
Example: | |||
<pre> | |||
"VGVzdA==".Base64Decode() | |||
Returns: "Test" | |||
</pre> | |||
|- | |||
||Base64Encode | |||
|| | |||
* Input string | |||
|| | |||
Encodes UTF8 bytes of a string using the base64 encoding. Encoding is done by converting the string into UTF8 bytes and encoding those bytes into base64. Returns an empty string for an empty input string. This encoding is needed e.g., in the http basic authentication. | |||
Example: | |||
<pre> | |||
"Test".Base64Encode() | |||
Returns: "VGVzdA==" | |||
</pre> | </pre> | ||
|- | |- | ||
Line 735: | Line 703: | ||
|} | |} | ||
== | == Timespan == | ||
Timespan represents a time interval (duration of time or elapsed time) that is measured as a positive or negative number of days, hours, minutes, seconds, and fractions of a second. The Timespan is not bound to calendar time, so a Timespan can be used to represent the time of day, but only if the time is unrelated to a particular date. | |||
Difference between two TimeStamps is | Difference between two TimeStamps is Timespan. TimeStamp added by Timespan is TimeStamp. | ||
Minimum possible value of a | Minimum possible value of a Timespan is -10 675 199 days 2 hours 48 minutes 5.4775808 seconds and maximum possible value is 10 675 199 days 2 hour 48 minutes 5.4775807 seconds. | ||
{| class="wikitable" | {| class="wikitable" | ||
!''' | !'''Timespan properties''' | ||
! '''Description''' | ! '''Description''' | ||
|- | |- | ||
||Ticks (Integer) | ||Ticks (Integer) | ||
||Number of ticks represented by the | ||Number of ticks represented by the Timespan. A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second. | ||
|- | |- | ||
||TotalDays (Float) | ||TotalDays (Float) | ||
|| | ||Timespan value in days (one day is 24 hours) (both whole and fractional). | ||
|- | |- | ||
||TotalHours (Float) | ||TotalHours (Float) | ||
|| | ||Timespan value in hours (both whole and fractional). | ||
|- | |- | ||
||TotalMilliseconds (Float) | ||TotalMilliseconds (Float) | ||
|| | ||Timespan value in milliseconds (both whole and fractional). | ||
|- | |- | ||
||TotalMinutes (Float) | ||TotalMinutes (Float) | ||
|| | ||Timespan value in minutes (both whole and fractional). | ||
|- | |- | ||
||TotalSeconds (Float) | ||TotalSeconds (Float) | ||
|| | ||Timespan value in seconds (both whole and fractional). | ||
|} | |} | ||
Line 773: | Line 741: | ||
! '''Description''' | ! '''Description''' | ||
|- | |- | ||
|| | ||Timespan | ||
|| | || | ||
# Days (Integer) | # Days (Integer) | ||
Line 781: | Line 749: | ||
# Milliseconds (Integer) | # Milliseconds (Integer) | ||
|| | || | ||
Creates a new [[ | Creates a new [[QPR_ProcessAnalyzer_Objects_in_Expression_Language#Timespan|Timespan]] object. Only the first parameter (number of days) is mandatory. By default, other parameters are assumed to be zero. | ||
Examples: | Examples: | ||
<pre> | <pre> | ||
Timespan(1) | |||
Returns: Time span for the duration of 1 day. | Returns: Time span for the duration of 1 day. | ||
Timespan(12,3,4,5,6) | |||
Returns: Time span for the duration of 12 days, 3 hours, 4 minutes, 5 seconds and 6 milliseconds. | Returns: Time span for the duration of 12 days, 3 hours, 4 minutes, 5 seconds and 6 milliseconds. | ||
</pre> | </pre> | ||
|- | |- | ||
|| | ||TimespanFromTicks | ||
|| | || | ||
# Number of ticks (Integer) | # Number of ticks (Integer) | ||
|| | || | ||
Creates a new [[ | Creates a new [[QPR_ProcessAnalyzer_Objects_in_Expression_Language#Timespan|Timespan]] object from an integer representing ticks. A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second. | ||
Examples: | Examples: | ||
<pre> | <pre> | ||
TimespanFromTicks(Timespan(12,3,4,5,6).Ticks) | |||
Returns: A time span object representing 12 days, 3 hours, 4 minutes, 5 seconds and 6 milliseconds. | Returns: A time span object representing 12 days, 3 hours, 4 minutes, 5 seconds and 6 milliseconds. | ||
</pre> | </pre> | ||
|} | |} | ||
== Dictionary == | |||
Dictionary represents a collection of key-value pairs, where the keys are unique within a dictionary. See also the [[QPR_ProcessAnalyzer_Expressions#Dictionary_literals|dictionary literal syntax]] and the [[QPR_ProcessAnalyzer_Expressions#Lookup_operator_.28.5B_.5D.29|lookup operator for dictionaries]]. | |||
Expression language is able to handle JSON by converting JSON strings into objects and objects into JSON strings. In the expression language, the object created from JSON strings, are dictionaries. | |||
{| class="wikitable" | |||
!'''Dictionary properties''' | |||
! '''Description''' | |||
|- | |||
||Count (Integer) | |||
||Returns the number of elements stored into this dictionary. | |||
|- | |||
||Keys | |||
||Returns the array of all the keys in this dictionary. | |||
|- | |||
||Values | |||
||Returns the array of all the values in this dictionary. | |||
|} | |||
{| class="wikitable" | |||
!'''Dictionary Functions''' | |||
!'''Parameters''' | |||
! '''Description''' | |||
|- | |||
||Add | |||
|| | |||
|| | |||
Adds possibly multiple values into the dictionary. Takes even number of parameters, where every odd parameter represents key. Every even parameter represents the value to be added for the preceding key. Returns the dictionary itself. | |||
Will throw an exception if a value with the same key already exists in the dictionary. | |||
<pre> | |||
Examples: | |||
ToDictionary().Add("a", 1, "b", 2).(Get("a") + Get("b")) | |||
Returns: 3 | |||
ToDictionary().Add("a", 1, "a", 2).Get("a") | |||
Throws an exception. | |||
</pre> | |||
|- | |||
||Clone (Dictionary) | |||
|| | |||
|| | |||
Creates a copy of a dictionary containing all items than in the original dictionary. Examples: | |||
<pre> | |||
ToDictionary().Clone() | |||
Returns: Copy of the original Dictionary object. | |||
ToDictionary(["a": 1, "b": 2]).Clone().Get("b") | |||
Returns: 2 | |||
let original = ToDictionary(["a": 1, "b": 2]); | |||
let cloned = original.Clone(); | |||
original.Set("a", 3); | |||
cloned.Get("a") | |||
Returns: 1 | |||
</pre> | |||
|- | |||
||ContainsKey | |||
||Key to search for (String) | |||
|| | |||
Check whether given key exists in the dictionary. Returns true only if there is a stored value for given key. | |||
Examples: | |||
<pre> | |||
ToDictionary().Set("a", 1).ContainsKey("a") | |||
Returns: True | |||
ToDictionary().Set("a", 1).ContainsKey("b") | |||
Returns: False | |||
</pre> | |||
|- | |||
||Get | |||
||Key to search for (String) | |||
|| | |||
Get the value associated with the given key from the dictionary. Returns the value associated with the key in the dictionary. Will throw an exception if there is no value associated with the given key in the dictionary. | |||
Examples: | |||
<pre> | |||
ToDictionary().Set("a", 1, "b", 2).Get("b") | |||
Returns: 2 | |||
ToDictionary().Set("a", 1, "b", 2).Get("c") | |||
Throws an exception. | |||
</pre> | |||
|- | |||
||Extend (Dictionary) | |||
||Dictionary | |||
|| | |||
Adds the values from another dictionary (or array of dictionaries) to this dictionary, and returns the dictionary itself. The function overwrites any possible earlier values in the dictionary. | |||
If the dictionary provided as a parameter, is not an array and the item is a dictionary, all the values of its keys will be added to the context dictionary. If the dictionary provided as a parameter is not an array and the item is an hierarchical array, all the values will be added to the context dictionary so that the last value in the array is used when duplicates exist. If the other dictionary is an array, all the items are added one-by-one using the procedure described earlier. | |||
Examples: | |||
<pre> | |||
#{}.Extend(#{"a": 1, "b": 2, "c": 5}) | |||
Returns: #{ "a": 1, "b": 2, "c": 5 } | |||
#{}.Extend(["a": 1, "b": 2, "a": 5]) | |||
Returns: #{ "a": 5, "b": 2 } | |||
#{"a": 1, "c": 3}.Extend(["a": 5, "b": 2]) | |||
Returns: #{ "a": 5, "b": 2, "c": 3 } | |||
#{}.Extend(EventLogById(1).Cases:Name) | |||
Returns: A dictionary containing all the cases in event log so that the case itself is a key and its name is the value. | |||
#{}.Extend(EventLogById(1).Cases.#{_: Name}) | |||
Returns: The same as above. | |||
</pre> | |||
|- | |||
||Remove | |||
||Key to remove (String) | |||
|| | |||
Removes value of given key from the dictionary. Returns true only if the a value associated with given key was found and successfully removed from the dictionary. | |||
Examples: | |||
<pre> | |||
ToDictionary().Set("a", 1, "b", 2).Remove("b") | |||
Returns: True | |||
ToDictionary().Set("a", 1, "b", 2).Remove("c") | |||
Returns: False | |||
Let("dictionary", ToDictionary().Set("a", 1, "b", 2)); | |||
dictionary.Remove("b"); | |||
dictionary.Keys | |||
Returns: ["a"] | |||
</pre> | |||
|- | |||
||Set | |||
|| | |||
|| | |||
Sets possibly multiple values into the dictionary. Will overwrite any possible earlier values the key had in the dictionary. Takes even number of parameters, where every odd parameter represents key. Every even parameter represents the value to be set for the preceding key. Returns the dictionary itself. | |||
Examples: | |||
<pre> | |||
ToDictionary().Set("a", 1, "b", 2).(Get("a") + Get("b")) | |||
Returns: 3 | |||
ToDictionary().Set("a", 1, "a", 2).Get("a") | |||
Returns: 2 | |||
</pre> | |||
|- | |||
||ToArray | |||
|| | |||
|| | |||
Converts dictionary object into a hierarchical array. Returns the dictionary object converted into a hierarchical array. | |||
Examples: | |||
<pre> | |||
ToDictionary().ToArray() | |||
Returls: [] | |||
ToDictionary().Add("a", 1, "b", 2).ToArray() | |||
Returns: [ "a": [1], "b": [2] ] | |||
</pre> | |||
|- | |||
||TryGetValue | |||
||Key to search for (String) | |||
|| | |||
Tries to get the value associated with the given key from the dictionary. If the key was found in the dictionary, returns the value associated with the key in the dictionary. Otherwise, returns _empty. | |||
Examples: | |||
<pre> | |||
ToDictionary().Set("a", 1, "b", 2).TryGetValue("b") | |||
Returns: 2 | |||
ToDictionary().Set("a", 1, "b", 2).TryGetValue("c") | |||
Returns: _empty | |||
</pre> | |||
|} | |||
JSON conversion functions: | |||
{| class="wikitable" | |||
!'''Function''' | |||
!'''Parameters''' | |||
! '''Description''' | |||
|- | |||
||ParseJson | |||
||json data (String) | |||
|| | |||
Converts given JSON string into an object. JSON objects are represented as Dictionary objects in the expression language. | |||
Examples: | |||
<pre> | |||
ParseJson("{\"a\": 1, \"b\": 2}")["b"] | |||
Returns: 2 | |||
Sum(ParseJson("[1, 2, 3, 4]")) | |||
Returns: 10 | |||
ToJson(ParseJson("{\"a\": 1, \"b\": 2}")) | |||
Returns: #{"a":1,"b":2} | |||
</pre> | |||
|- | |||
||ToJson | |||
||Object | |||
|| | |||
Converts given object into JSON. It is recommended that hierarchical arrays and objects are first converted to dictionaries before converting to JSON since JSON does not have exactly identical construct and thus converting JSON back to expression object will not result object similar to the original. | |||
Examples: | |||
<pre> | |||
ToJson(ParseJson("{\"a\": 1, \"b\": 2}")) | |||
Returns: #{"a":1,"b":2} | |||
ToJson(ToDictionary().Set("a", 1, "b", 2)) | |||
Returns: #{"a":1,"b":2} | |||
ToJson([1,[[2,ToDictionary().Set("a", 1)],4]]) | |||
Returns: [1,[[2,#{"a":1}],4]] | |||
ToJson(null) | |||
Returns: null | |||
ToJson(_empty) | |||
Returns: #{} | |||
ToJson(["a": 1, "b": 2]) | |||
Returns: [#{"Root":"a","Array":[1]},#{"Root":"b","Array":[2]}] | |||
</pre> | |||
|} | |||
{| class="wikitable" | |||
!'''Function''' | |||
!'''Parameters''' | |||
! '''Description''' | |||
|- | |||
||ToDictionary | |||
|| | |||
# Hierarchical object | |||
# convert array of length one to scalar (boolean) | |||
|| | |||
Converts given hierarchical array into Dictionary. In the returned dictionary each hierarchical array element has a corresponding key-value pair. All the elements in the array that don't have context specified will be ignored. The parameter can also be an existing dictionary, which will create a copy of the dictionary. | |||
The second parameters is an optional value to define how to interpret hierarchical array values having array length of 1. If enabled (=true, default value), the generated dictionary will have all its values initialized as arrays of values, except if the array is of length, in which case the value of that single array item will be used as dictionary value. If disabled, all the values will be stored as arrays in the dictionary. | |||
Throws an exception if the parameter is specified but is not an array. | |||
Examples: | |||
<pre> | |||
ToDictionary() | |||
Returns: <empty dictionary object> | |||
ToDictionary(["a": 1, "b": 2]).Get("b") | |||
Returns: 2 | |||
ToDictionary(["a": [1, 2], "b": [2, 3]]).Get("b") | |||
Returns: [2, 3] | |||
ToDictionary(["a": 1, "b": 2], false).Get("b") | |||
Returns: [2] | |||
ToDictionary(["a": [1], "b": [2]], false).Get("b") | |||
Returns: [2] | |||
ToDictionary(["a": [1, 2], "b": [2, 3]], false).Get("b") | |||
Returns: [2, 3] | |||
ToDictionary(["a": 1, 2]).ToArray() | |||
Returns: ["a": 1] | |||
</pre> | |||
|} | |||
== Exception == | |||
Exception is an object that is thrown when an error occurs in an expression. The exception object can be caught with the [[QPR_ProcessAnalyzer_Expressions#Catching_exceptions|try-catch]] statement and information regarding the error is available as properties of the exception object. | |||
{| class="wikitable" | |||
!'''Exception properties''' | |||
! '''Description''' | |||
|- | |||
||Context | |||
||Returns the exception context stack. | |||
|- | |||
||Details | |||
||Additional exception type specific details in a dictionary. | |||
|- | |||
||ExceptionCode | |||
||Numeric code of the exception. The code is ''null'' if the exception doesn't have an exception code. | |||
|- | |||
||InnerExceptions | |||
||Returns an array of additional exception objects representing inner exceptions, e.g., when the type of an exception is ''AggregationException''. Returns ''null'' if there are no inner exceptions. | |||
|- | |||
||Message | |||
||Returns a user-readable message describing the exception. | |||
|- | |||
||SourceColumn | |||
||Returns the column in source code where exception occurred. | |||
|- | |||
||SourceLine | |||
||Returns the line in source code where exception occurred. | |||
|- | |||
||ThrownObject | |||
||Returns the object that was thrown using the [[QPR_ProcessAnalyzer_Expressions#Throwing_objects|throw]] statement. Value is ''null'' if exception didn't originate from throwing an object. | |||
|- | |||
||Timestamp | |||
||Returns time when the exception occurred. | |||
|- | |||
||Type | |||
||Returns textual exception type identifier. | |||
|} | |||
Example: Try to divide by zero, catch the exception and read the exception message: | |||
<pre> | |||
try { | |||
1 / 0; | |||
} catch (error) { | |||
return error.Message; | |||
} | |||
</pre> |
Latest revision as of 18:02, 26 April 2024
Array
See introduction to arrays. Following list contains all array related functions.
Function | Parameters | Description |
---|---|---|
Array |
|
Creates a new array where the provided parameters are items of the array. There can be any number of parameters. Note: arrays can also be created using [] syntax. Examples: Array(1, 2, 3) Returns: An array having three elements which are 1, 2 and 3. Also following syntax can be used: [1, 2, 3] Array() Returns: An empty array. |
Concat (Array) |
Hierarchical object |
Concatenate multiple arrays together into one. Returns a single array which contains all the arrays given as parameter concatenated together in the same order they were given. If a parameter is not an array, it will be converted into an array having only the given element. Examples: Concat(1, [DateTime(2017), 3], [4, "foo"], "bar") Returns: [1, DateTime(2017), 3, 4, "foo", "bar"] |
ConcatTop (Hierarchical object) |
Hierarchical object |
Concatenate the topmost arrays in a given hierarchical object. Returns a new hierarchical object with the contents of the topmost level concatenated and removed. Examples: ConcatTop([ 0, [1,2], [3], [4,[6,7]] ]) Returns: [1, 2, 3, 4, [6, 7]] ConcatTop([ [1,[2,3]], [4,[6,7]] ]) Returns: [1, [2, 3], 4, [6, 7]] |
CountTop (Integer) |
Hierarchical object |
Get the number of elements in the topmost level array of a given array or hierarchical object. If the parameter is not an array, zero is returned. Examples: CountTop([ 0, [1,2], [3], [4,[6,7]] ]) Returns: 4 CountTop([[1,[2,3]],[4,[6,7]]]) Returns: 2 CountTop(0) Returns: 0 |
Distinct |
Array or hierarchical object |
Modify given array by filtering out all duplicate values leaving only distinct values in the input array into the result. If given a hierarchical object, applies the function at the level that is one level up from the leaf level. Examples: Distinct([1]) Returns: [1] Distinct([1, 1]) Returns: [1] Distinct([1, 1, 2, 2]) Returns: [1, 2] Distinct([1, 1, 2, 2, "a", DateTime(2017), DateTime(2017), "b", DateTime(2016), "a"]) Returns: [1, 2, "a", DateTime(2017), "b", DateTime(2016)] |
Except |
|
Creates an substract given items from an array. Returns a single array which contains all the elements that were in the first array that were not in any of the subsequent arrays. If a parameter is not an array, it will be converted into an array having only the given element. Examples: Except([1, 2, "a", DateTime(2017), 5, "b", 6], ["a", 2, 3, DateTime(2017), 5], [DateTime(2017), "a", 2, 6]) Returns: [1, "b"] |
First (Object) | Array |
Gets the first item in the array. If array has no items, returns _empty. Examples: First([1,2,3,4]) returns 1. First([]) returns _empty. |
GetAt (Object) |
|
Returns element at given index from the beginning of the array. The first item has index zero. If given a hierarchical object, returns the element at given index of the root level array. Throws a calculation exception if the given index does not exist in given object or given object is not an array. Examples: GetAt(0, [1,2,3]) Returns: 1 GetAt(1, [[1, 2], [3, 4]]) Returns: [3, 4] GetAt(1, [[[5, 6]], [[1, 2], [3, 4]]]) Returns: [[1, 2], [3, 4]] GetAt(1, GetAt(1, [[[5, 6]], [[1, 2], [3, 4]]])) Returns: [3, 4] |
GetAtReverse (Object) |
|
Same as the GetAt function, except that the index is calculated from the end of the array. |
In (Boolean) |
Array where to search the object |
Checks whether the current context object exists in given array, and returns either true or false. Note that the searched object is not given as a parameter, but it's the context object for the function. Examples: 1.In([1,2,3]) Returns: true [1].In([[1],2,3]) Returns: false DateTime(2017).In([DateTime(2016), DateTime(2017)]) Returns: true Count(eventLog.Events.TimeStamp.DateTime(_.Year).In([DateTime(2012)]).Where(_==true)) Returns: The number of events there are in the given event log that have time stamp for year 2012. |
Intersect |
|
Creates an intersection of multiple arrays. Returns a single array which contains an intersection of all the items in all the arrays given as parameter. If a parameter is not an array, it will be converted into an array having only the given element. Examples: Intersect([1, 2, "a", DateTime(2017), 5], ["a", 2, 3, DateTime(2017), 5], [DateTime(2017), "a", 2]) Returns: [2, "a", DateTime(2017)] |
IndexOf (Integer) |
|
Gets the index of the first occurrence of the item in the array. If the item is not found, -1 is returned. Parameters:
Examples: IndexOf(["the", "fox", "jumps", "over", "the", "dog"], "the") returns 0. IndexOf(["the", "fox", "jumps", "over", "the", "dog"], "the", 1) returns 4. IndexOf(["the", "fox", "jumps", "over", "the", "dog"], "the", 5) returns -1. IndexOf(["the", "fox", "jumps", "over", "the", "dog"], "a") returns -1. |
IndexOfSubArray (Integer*) |
|
Returns indexes of the given sub-array (1. parameter) within the given main-array (2. parameter). The function returns starting indexes of all the occurrences of given sub-array within given main-array. If only the first parameter is given, the array in the current context object is used as the main-array. Examples: IndexOfSubArray([4], [1,2,3,4,1,2,5]) Return: 3 IndexOfSubArray([1,2], [1,2,3,4,1,2,5]) Return: [0, 4] IndexOfSubArray([1,2,4], [1,2,3,4,1,2,5]) Returns: [] [[1,2,3,4,1,2,5]].IndexOfSubArray([1,2]) Return: [0, 4] |
IsArray (Boolean) |
Object to check |
Tests whether given object is an array or hierarchical object. Returns true if it is. Examples: ForEach("item", [1, "a", null, [1,2,3], ["foo":[null,"a"], "bar":[2,null]]], IsArray(item)) Returns: [false, false, false, true, true] |
Last (Object) | Array |
Gets the last item in the array. If array has no items, returns _empty. Examples: Last([1,2,3,4]) returns 4. Last([]) returns _empty. |
LastIndexOf (Integer) |
|
Gets the index of the last occurrence of the item in the array. If the item is not found, -1 is returned. Parameters:
Examples: LastIndexOf(["the", "fox", "jumps", "over", "the", "dog"], "the") returns 4. LastIndexOf(["the", "fox", "jumps", "over", "the", "dog"], "the", 3) returns 0. LastIndexOf(["the", "fox", "jumps", "over", "the", "dog"], "a") returns -1. |
Reverse (Array) | Array to reverse | Reverses an array, i.e. returns a new array, where items are in the inverse order comparing to the original array.
Example: Reverse([1, 2, 3]) Returns [3, 2, 1] |
Shuffle (Array) |
Array to be shuffled |
Shuffles the given array into a random order. Returns an array with the same items as in the input array, but in random order. Examples: Shuffle([1, 2]) Returns: Either [1, 2] or [2, 1] both in about 50% of the calls. Shuffle(NumberRange(0, 99))[NumberRange(0, 9)] Returns: An array containing 10 random unique values between 0 and 99 ("Random sample of size 10"). |
StringJoin (String) |
|
Joins the given array of values (converted to strings) by using given separator into a single string. If given a hierarchical object, applies the function as described in at the level that is one level up from the leaf level. The depth of the result is one level less than the object that was given as parameter. Examples: StringJoin(", ", [1,null,"foo",DateTime(2017)]) Returns: 1, , foo, 01/01/2017 00:00:00 StringJoin(", ", [[1,2], [3,4]]) Returns: ["1, 2", "3, 4"] |
Union |
|
Creates an union of multiple arrays. Returns a single array which contains an union of all the items in all the arrays given as parameter. If a parameter is not an array, it will be converted into an array having only the given element. Examples: Union([1, 2, "a", DateTime(2017), 5], ["a", 2, 3, DateTime(2017), 5], [DateTime(2017), "a", 2, "b"]) Returns: [1, 2, "a", DateTime(2017), 5, 3, "b"] |
Zip (Array) |
Arrays to be combined |
Combines multiple arrays into a single array. All the input arrays must be of the same length. Returns an array where the number of elements equal to the number of elements in each of the input arrays. All elements in the Nth position of the array are the concatenated values of Nth elements of each of the input arrays. Examples: Zip([1,2,3,4], [5,6,7,8], [9,10,11,12]) Returns: [[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]] Zip([1,2], [3,4], [5,6]) Returns: [[1, 3, 5], [2, 4, 6]] Zip([1,2,3]) Returns: [[1], [2], [3]] Zip([[1],[2],[3]]) Returns: [[1,2,3]] Zip([]) Returns: [] Zip([1], [4,5], [7,8,9]) Gives an error |
DateTime
DateTime represents a precise timestamp.
DateTime properties | Description |
---|---|
Day (Integer) | The day of the calendar month. Number between 1 and 31. Based on QPR ProcessAnalyzer server local time. |
Hour (Integer) | The hour component of the date. Number between 0 and 23. Based on QPR ProcessAnalyzer server local time. |
Millisecond (Integer) | The millisecond component of the date. Number between 0 and 999. Based on QPR ProcessAnalyzer server local time. |
Minute (Integer) | The minute component of the date. Number between 0 and 59. Based on QPR ProcessAnalyzer server local time. |
Month (Integer) | The calendar month component of the date. Number between 1 and 12. Based on QPR ProcessAnalyzer server local time. |
Second (Integer) | The second component of the date. Number between 0 and 59. Based on QPR ProcessAnalyzer server local time. |
Ticks (Integer) | Number of ticks in the date. The value of this property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001 (0:00:00 UTC on January 1, 0001, in the Gregorian calendar). A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second. |
UnixMilliseconds (Integer) | Returns the time as Unix compatible milliseconds (i.e., milliseconds from the first of January 1970 midnight UTC). |
WeekOfYear (Integer) | Week number of the date (according to the ISO standard). Number between 1 and 53. |
Year (Integer) | The year component of the date. Number between 1 and 9999. Based on QPR ProcessAnalyzer server local time. |
DateTime functions | Parameters | Description |
---|---|---|
Round (DateTime) |
|
Rounds given date time by given Timespan or given number of seconds. Example: Round to the nearest hour: Round(DateTime(2017, 1, 1, 14, 48), Timespan(0, 1)) DateTime(2017, 1, 2, 3, 4, 5).Round(10) Returns: DateTime(2017, 1, 2, 3, 4, 10) DateTime(2017, 1, 2, 3, 4, 5).Round(Timespan(1)) Returns: DateTime(2017, 1, 2) |
Truncate (DateTime) |
|
Truncates given DateTime value to given precision. Truncating means that the provided DateTime (i.e. timestamp) is converted into a timestamp representing the beginning of the period. For example, if period is year, the Truncate function returns the first date of the year where the input DateTime is belonging. Truncate function is useful e.g. when dimensioning data into different periods. Supported precision values are: year, quarter, month, week, day, hour, minute and second. Examples: DateTime(2018, 5, 14, 3, 4, 5).Truncate("year") Returns: DateTime(2018) DateTime(2018, 5, 20, 3, 4, 5).Truncate("quarter") Returns: DateTime(2018, 4, 1) DateTime(2019, 8, 14, 3, 4, 5).Truncate("day") Returns: DateTime(2019, 8, 14) DateTime(2019, 8, 14, 3, 4, 5).Truncate("hour") Returns: DateTime(2019, 8, 14, 3) |
The following functions can be used to initialize DateTime objects:
Function | Parameters | Description |
---|---|---|
DateTime |
|
Creates a new DateTime object. Only the first (year) parameter is mandatory. Examples: DateTime(2017) Returns: A datetime for 1st January 2017 at 0:00:00. DateTime(2017, 5) Returns: A datetime for 5th January 2017 at 0:00:00. DateTime(2017, 5, 6, 13, 34, 56, 123) Returns: A date time object for 6th May 2017 at 13:34:56.123. |
DateTimeFromTicks |
Number of ticks (Integer) |
Creates a new DateTime object from an integer representing ticks. A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second. Examples: DateTimeFromTicks(DateTime(2018, 5, 6, 13, 34, 56, 123).Ticks) Returns: A date time object for 6th May 2018 at 13:34:56.123. |
ParseDateTime |
|
Converts the given string to a DateTime using the provided date format. If the parsing fails, an exception is thrown. The second parameter defines the date format used for conversion. More information: https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings. Examples: ParseDateTime("01.01.2020", "dd.MM.yyyy") Returns 01.01.2020 as datetime. ParseDateTime("2020/01/01", "dd.MM.yyyy") Throws an exception. |
The following properties can be used to initialize DateTime objects:
Property | Description |
---|---|
Now (DateTime) | DateTime object representing the current date and time. |
String
String properties | Description |
---|---|
Length |
Return the number of characters in the input string. Example: "Test".Length Returns: 4. "".Length Returns: 0. |
String functions | Parameters | Description |
---|---|---|
CharAt |
|
Return a character (as a String) in the index number position in the input string. The indexing starts from zero. Negative index numbers are not allowed. Examples: "test".CharAt(1) Returns: "e" "test".For("i", 0, i < Length, i + 1, CharAt(i)) Returns: ["t", "e", "s", "t"] |
Contains |
|
Returns true if the input string contains the searched string; otherwise false. String comparison is case sensitive. Example: "test".Contains("st") Returns: true |
Base64Decode |
|
Decodes a base64 string into a normal string by interpreting the data as UTF8. Encoding is done by converting the base64 string into bytes and converting those bytes into string by interpreting them as UTF8 encoded data. Returns an empty string for an empty input base64 string. Example: "VGVzdA==".Base64Decode() Returns: "Test" |
Base64Encode |
|
Encodes UTF8 bytes of a string using the base64 encoding. Encoding is done by converting the string into UTF8 bytes and encoding those bytes into base64. Returns an empty string for an empty input string. This encoding is needed e.g., in the http basic authentication. Example: "Test".Base64Encode() Returns: "VGVzdA==" |
EndsWith |
|
Return true if the input string ends with the searched string; otherwise false. String comparison is case sensitive. "test".EndsWith("st") Returns: true |
IndexOf |
|
Return the index number of the first occurrence of the searched string in the input string. Indexing starts from zero. If the start index is provided, the search is started from that index. The function returns -1 if match is not found. The start index is optional. Invalid start index is negative or more than input string length. Examples: "test".IndexOf("t") Returns: 0 "test".IndexOf("t", 1) Returns: 3 |
LastIndexOf |
|
Return the index number of the last occurrence of the searched string in the input string. Indexing starts from zero. If the start index is provided, the search is started from that index (calculated from the start of the string) towards the beginning of the string. Return -1 if match not found. Invalid start index is negative or more than input string length. |
Replace |
|
Replaces all occurrences of the first string with the second string in the input string. String comparison is case sensitive. Example: "abcd".Replace("b", "e") Returns: "aecd" |
Split |
|
Splits input string into array of substrings. The string is splitted based on a character or array of characters (that are provided as strings). String comparison is case sensitive. When remove empties parameter is true, empty strings are excluded (by default false). Examples: "1,2,3".Split([","]).ToInteger(_) Returns: [1,2,3] "a,b,,c".Split(",", true) Returns: ["a","b","c"] "a,b,,c".Split(",") Returns: ["a","b","","c"] |
StartsWith |
|
Return true if the input string starts with the searched string; otherwise false. String comparison is case sensitive. "test".StartsWith("t") Returns: true |
Substring |
|
Returns a substring of the input string starting from the start index. If the length is provided, the returned string contains maximum of that number of characters. Invalid start index is negative or more than input string length. Invalid length is negative or start index plus length is more then input string length. "Test123".Substring(4) Returns: "123" "Test123".Substring(4, 2) Returns: "12" |
ToLower | [none] | Return a string where all the characters of the input string have been converted to lower case characters.
"Test".ToLower() Returns: "test" |
ToUpper | [none] | Return a string where all the characters of the input string have been converted to upper case characters. |
Trim |
|
Removes spaces from the start and end of the input string (if array of strings is not provided). If the array of strings is provided, all leading and trailing characters in the array of strings are removed from the input string. Accepts also a single string in which case it is treated as if an array containing only that string was given as parameter. Examples: " Test".Trim() Returns: "Test" "Test".Trim(["T", "t"]) Returns: "es" "Test".Trim("t") Returns: "Tes" |
Timespan
Timespan represents a time interval (duration of time or elapsed time) that is measured as a positive or negative number of days, hours, minutes, seconds, and fractions of a second. The Timespan is not bound to calendar time, so a Timespan can be used to represent the time of day, but only if the time is unrelated to a particular date.
Difference between two TimeStamps is Timespan. TimeStamp added by Timespan is TimeStamp.
Minimum possible value of a Timespan is -10 675 199 days 2 hours 48 minutes 5.4775808 seconds and maximum possible value is 10 675 199 days 2 hour 48 minutes 5.4775807 seconds.
Timespan properties | Description |
---|---|
Ticks (Integer) | Number of ticks represented by the Timespan. A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second. |
TotalDays (Float) | Timespan value in days (one day is 24 hours) (both whole and fractional). |
TotalHours (Float) | Timespan value in hours (both whole and fractional). |
TotalMilliseconds (Float) | Timespan value in milliseconds (both whole and fractional). |
TotalMinutes (Float) | Timespan value in minutes (both whole and fractional). |
TotalSeconds (Float) | Timespan value in seconds (both whole and fractional). |
The following functions can be used to initialize Timespan objects.
Function | Parameters | Description |
---|---|---|
Timespan |
|
Creates a new Timespan object. Only the first parameter (number of days) is mandatory. By default, other parameters are assumed to be zero. Examples: Timespan(1) Returns: Time span for the duration of 1 day. Timespan(12,3,4,5,6) Returns: Time span for the duration of 12 days, 3 hours, 4 minutes, 5 seconds and 6 milliseconds. |
TimespanFromTicks |
|
Creates a new Timespan object from an integer representing ticks. A single tick represents one hundred nanoseconds or one ten-millionth of a second. There are 10,000 ticks in a millisecond, or 10 million ticks in a second. Examples: TimespanFromTicks(Timespan(12,3,4,5,6).Ticks) Returns: A time span object representing 12 days, 3 hours, 4 minutes, 5 seconds and 6 milliseconds. |
Dictionary
Dictionary represents a collection of key-value pairs, where the keys are unique within a dictionary. See also the dictionary literal syntax and the lookup operator for dictionaries.
Expression language is able to handle JSON by converting JSON strings into objects and objects into JSON strings. In the expression language, the object created from JSON strings, are dictionaries.
Dictionary properties | Description |
---|---|
Count (Integer) | Returns the number of elements stored into this dictionary. |
Keys | Returns the array of all the keys in this dictionary. |
Values | Returns the array of all the values in this dictionary. |
Dictionary Functions | Parameters | Description |
---|---|---|
Add |
Adds possibly multiple values into the dictionary. Takes even number of parameters, where every odd parameter represents key. Every even parameter represents the value to be added for the preceding key. Returns the dictionary itself. Will throw an exception if a value with the same key already exists in the dictionary. Examples: ToDictionary().Add("a", 1, "b", 2).(Get("a") + Get("b")) Returns: 3 ToDictionary().Add("a", 1, "a", 2).Get("a") Throws an exception. | |
Clone (Dictionary) |
Creates a copy of a dictionary containing all items than in the original dictionary. Examples: ToDictionary().Clone() Returns: Copy of the original Dictionary object. ToDictionary(["a": 1, "b": 2]).Clone().Get("b") Returns: 2 let original = ToDictionary(["a": 1, "b": 2]); let cloned = original.Clone(); original.Set("a", 3); cloned.Get("a") Returns: 1 | |
ContainsKey | Key to search for (String) |
Check whether given key exists in the dictionary. Returns true only if there is a stored value for given key. Examples: ToDictionary().Set("a", 1).ContainsKey("a") Returns: True ToDictionary().Set("a", 1).ContainsKey("b") Returns: False |
Get | Key to search for (String) |
Get the value associated with the given key from the dictionary. Returns the value associated with the key in the dictionary. Will throw an exception if there is no value associated with the given key in the dictionary. Examples: ToDictionary().Set("a", 1, "b", 2).Get("b") Returns: 2 ToDictionary().Set("a", 1, "b", 2).Get("c") Throws an exception. |
Extend (Dictionary) | Dictionary |
Adds the values from another dictionary (or array of dictionaries) to this dictionary, and returns the dictionary itself. The function overwrites any possible earlier values in the dictionary. If the dictionary provided as a parameter, is not an array and the item is a dictionary, all the values of its keys will be added to the context dictionary. If the dictionary provided as a parameter is not an array and the item is an hierarchical array, all the values will be added to the context dictionary so that the last value in the array is used when duplicates exist. If the other dictionary is an array, all the items are added one-by-one using the procedure described earlier. Examples: #{}.Extend(#{"a": 1, "b": 2, "c": 5}) Returns: #{ "a": 1, "b": 2, "c": 5 } #{}.Extend(["a": 1, "b": 2, "a": 5]) Returns: #{ "a": 5, "b": 2 } #{"a": 1, "c": 3}.Extend(["a": 5, "b": 2]) Returns: #{ "a": 5, "b": 2, "c": 3 } #{}.Extend(EventLogById(1).Cases:Name) Returns: A dictionary containing all the cases in event log so that the case itself is a key and its name is the value. #{}.Extend(EventLogById(1).Cases.#{_: Name}) Returns: The same as above. |
Remove | Key to remove (String) |
Removes value of given key from the dictionary. Returns true only if the a value associated with given key was found and successfully removed from the dictionary. Examples: ToDictionary().Set("a", 1, "b", 2).Remove("b") Returns: True ToDictionary().Set("a", 1, "b", 2).Remove("c") Returns: False Let("dictionary", ToDictionary().Set("a", 1, "b", 2)); dictionary.Remove("b"); dictionary.Keys Returns: ["a"] |
Set |
Sets possibly multiple values into the dictionary. Will overwrite any possible earlier values the key had in the dictionary. Takes even number of parameters, where every odd parameter represents key. Every even parameter represents the value to be set for the preceding key. Returns the dictionary itself. Examples: ToDictionary().Set("a", 1, "b", 2).(Get("a") + Get("b")) Returns: 3 ToDictionary().Set("a", 1, "a", 2).Get("a") Returns: 2 | |
ToArray |
Converts dictionary object into a hierarchical array. Returns the dictionary object converted into a hierarchical array. Examples: ToDictionary().ToArray() Returls: [] ToDictionary().Add("a", 1, "b", 2).ToArray() Returns: [ "a": [1], "b": [2] ] | |
TryGetValue | Key to search for (String) |
Tries to get the value associated with the given key from the dictionary. If the key was found in the dictionary, returns the value associated with the key in the dictionary. Otherwise, returns _empty. Examples: ToDictionary().Set("a", 1, "b", 2).TryGetValue("b") Returns: 2 ToDictionary().Set("a", 1, "b", 2).TryGetValue("c") Returns: _empty |
JSON conversion functions:
Function | Parameters | Description |
---|---|---|
ParseJson | json data (String) |
Converts given JSON string into an object. JSON objects are represented as Dictionary objects in the expression language. Examples: ParseJson("{\"a\": 1, \"b\": 2}")["b"] Returns: 2 Sum(ParseJson("[1, 2, 3, 4]")) Returns: 10 ToJson(ParseJson("{\"a\": 1, \"b\": 2}")) Returns: #{"a":1,"b":2} |
ToJson | Object |
Converts given object into JSON. It is recommended that hierarchical arrays and objects are first converted to dictionaries before converting to JSON since JSON does not have exactly identical construct and thus converting JSON back to expression object will not result object similar to the original. Examples: ToJson(ParseJson("{\"a\": 1, \"b\": 2}")) Returns: #{"a":1,"b":2} ToJson(ToDictionary().Set("a", 1, "b", 2)) Returns: #{"a":1,"b":2} ToJson([1,[[2,ToDictionary().Set("a", 1)],4]]) Returns: [1,[[2,#{"a":1}],4]] ToJson(null) Returns: null ToJson(_empty) Returns: #{} ToJson(["a": 1, "b": 2]) Returns: [#{"Root":"a","Array":[1]},#{"Root":"b","Array":[2]}] |
Function | Parameters | Description |
---|---|---|
ToDictionary |
|
Converts given hierarchical array into Dictionary. In the returned dictionary each hierarchical array element has a corresponding key-value pair. All the elements in the array that don't have context specified will be ignored. The parameter can also be an existing dictionary, which will create a copy of the dictionary. The second parameters is an optional value to define how to interpret hierarchical array values having array length of 1. If enabled (=true, default value), the generated dictionary will have all its values initialized as arrays of values, except if the array is of length, in which case the value of that single array item will be used as dictionary value. If disabled, all the values will be stored as arrays in the dictionary. Throws an exception if the parameter is specified but is not an array. Examples: ToDictionary() Returns: <empty dictionary object> ToDictionary(["a": 1, "b": 2]).Get("b") Returns: 2 ToDictionary(["a": [1, 2], "b": [2, 3]]).Get("b") Returns: [2, 3] ToDictionary(["a": 1, "b": 2], false).Get("b") Returns: [2] ToDictionary(["a": [1], "b": [2]], false).Get("b") Returns: [2] ToDictionary(["a": [1, 2], "b": [2, 3]], false).Get("b") Returns: [2, 3] ToDictionary(["a": 1, 2]).ToArray() Returns: ["a": 1] |
Exception
Exception is an object that is thrown when an error occurs in an expression. The exception object can be caught with the try-catch statement and information regarding the error is available as properties of the exception object.
Exception properties | Description |
---|---|
Context | Returns the exception context stack. |
Details | Additional exception type specific details in a dictionary. |
ExceptionCode | Numeric code of the exception. The code is null if the exception doesn't have an exception code. |
InnerExceptions | Returns an array of additional exception objects representing inner exceptions, e.g., when the type of an exception is AggregationException. Returns null if there are no inner exceptions. |
Message | Returns a user-readable message describing the exception. |
SourceColumn | Returns the column in source code where exception occurred. |
SourceLine | Returns the line in source code where exception occurred. |
ThrownObject | Returns the object that was thrown using the throw statement. Value is null if exception didn't originate from throwing an object. |
Timestamp | Returns time when the exception occurred. |
Type | Returns textual exception type identifier. |
Example: Try to divide by zero, catch the exception and read the exception message:
try { 1 / 0; } catch (error) { return error.Message; }