Topics
Expression Reference
In this article
Expressions are pieces of custom functionality which you can use in several places in your app, e.g. as an expression property in a model.
Robert van Boesschoten
Published: 10-10-2019
Last updated: 10-09-2020
Read this reference if you would like to know what kind of expressions there are. If you would like to know how to create expression properties in your data model, take a look at our tutorial article HowTo create expression properties?
All basic mathematical operators can be used in expressions. Take a look below! If you want to use a variable in an expression, you can use `var:` followed by the name of the variable. In this example, we're using the variables a and b.
You can also use the words `and` - `or` instead of the operators `&` and `|`.
Also, you can use brackets `( )` in the same way you'd use brackets in mathematics. Please notice the difference between `2 + 2 * 2 = 6` and `(2 + 2) * 2 = 8`. This is the same for `var:a + var:a * var:a = 6 and (var:a + var:a) * var:a = 8`.
Below is an overview of all expressions in Betty Blocks, in alphabetical order.
Checks if there are blank values in the collection. Returns true or false.
var:collection = ["Betty", "Blocks", ""] any_blank?(var:collection) >>> true
var:collection = ["Betty", "Blocks", "Alkmaar"] any_blank?(var:collection) >>> false
var:collection = [] any_blank?(var:collection) >>> false
Checks if value is present in the collection. Returns true or false.
var:collection = ["Betty", "Blocks"] any_include?(var:collection, "Blocks") >>> true
var:collection = ["Betty", "Blocks"] any_include?(var:collection, "Alkmaar") >>> false
Checks if there are nil values in the collection. Returns true or false.
var:collection = ["Betty", "Blocks", nil] any_nil?(var:collection) >>> true
var:collection = ["Betty", "Blocks", ""] any_nil?(var:collection) >>> false
var:collection = [] any_nil?(var:collection) >>> true
Note: There's a difference between nil and "" (blank).
Checks if there are non-blank values in the collection. Returns true or false.
var:collection = ["Betty", "Blocks", ""] any_not_blank?(var:collection) >>> true
var:collection = ["", "", ""] any_not_blank?(var:collection) >>> false
var:collection = [] any_not_blank?(var:collection) >>> false
Checks if there are non-nil values in the collection. Returns true or false.
var:collection = ["Betty", "Blocks", nil] any_not_nil?(var:collection) >>> true
var:collection = ["Betty", "Blocks", ""] any_not_nil?(var:collection) >>> true
var:collection = [] any_not_nil?(var:collection) >>> false
Note: There's a difference between nil and "" (blank).
Checks if there's any objects starting with the value entered in the expression.
var:collection = ["Betty", "Blocks", "Alkmaar"] any_starts_with?(var:collection, "Alk") >>> true
var:collection = ["Betty", "Blocks", "Alkmaar"] any_starts_with?(var:collection, "Atlan") >>> false
Returns the object/record corresponding to the number in an array/collection, where 0 is the first.
var:collection = [ "a", "b", "c" ] var:collection[1] >>> "b"
Note: Text values need to be quoted when used in variables, numeric values don't. Note the difference in `[1, 2, 3]` and `["a", "b", "c"]`. Double or single quotes both suffice.
Returns the average of an array of numbers.
var:array = [1, 2, 3] avg(var:array) >>> 2
You can use this to decode a base64 text or a base64 file.To assign to a file property, you'll need to do the decode expression in an URL expression.
var:base64 = base64_encode("test") >>> "dGVzdA=="
base64_decode(var:base64, "string") >>> "test"
base64_decode(var:base64) >>> file with random name and extension based on the input
base64_decode(var:base64, "file") >>> file with random name and extension based on the input
base64_decode(var:base64, "file", "txt") >>> file with random name and .txt extension
base64_decode(var:base64, "file", "custom_name.txt") >>> file named 'custom_name.txt'
The third parameter is considered to be a file with extension, when the name contains a `.`.
When decoding with the `"file"` option, a temporary file will be generated. At the end of the action, this file will be discarded, so make sure to assign it if you need it.
`base64_encode()` lets you encode a file or text in base64 format. Base64 encoding is used in several web services, but is also a good way to transfer files.
base64_encode("test") >>> "dGVzdA=="base64_encode(var:file)
Returns the date of the first of the month from the given date.
beginning_of_month(10-03-12 13:41) >>> 01-03-12
Checks if a record or variable exists. Returns false if the record or variable exists.
var:record.name = "Robert" blank?(var:record.name) >>> false blank?(var:record) >>> false
`blank?(var:record)` is the direct opposite of `present?(var:record)`
Checks if a value matches a Regex. Returns true or false.
var:value = "Betty Blocks!" boolean_match(var:value, "^[A-Za-z0-9 _.!]+$") >>> true boolean_match(var:value, "^[A-Za-z0-9 _.]+$") >>> false
Returns a date which is the date + the given business days (/weekdays).
business_days_offset(2019-04-10,6) >>> 2019-04-18
Changes the first letter of a string to a capital.
capitalize("betty blocks") >>> Betty blocks
Returns the next highest integer value by rounding up value if necessary.
ceil(9.2) >>> 10 ceil(4.6) >>> 5
Combines the values of an array. The second parameter defines the addition between the values.
concat(["Betty","Blocks","Alkmaar"], " / ") >>> Betty / Blocks / Alkmaar
concat(var:employees.name, " | ") >>> Robert | Thom | Marcel
Returns the number of items in an array and hash, or returns the number of characters in a string.
var:a = ["a", "b", "c", "d"]count(var:a) >>> 4 count([1,2,3]) >>> 3
var:b = {a: 1, b: 2, c: 3} count(var:b) >>> 3
var:c = "This is text" count(var:c) >>> 12
Count the number of records in a collection, ignoring the set limit, without rendering the full collection.
All records: Robert, Marcel, Thomas, Jermel, Ralph, Chris var:collection_with_limit_4 = Robert / 3 Marcel / 6 Thomas / 9 Jermel / 12 count_full_collection(var:collection_with_limit_4) >>> 6
Returns the day from a specific date as a number expression.
day(2019-05-01) >>> 1
day(2019-05-20) >>> 20
Use an amount of days in a calculation.
var:date = 2019-01-01
var:date + days(2) >>> 2019-01-03
Returns a date, which is the date + the given days.
days_offset(2019-04-10,10) >>> 2019-04-20
Decodes a JSON Web Token.
var:algorithm = "HS256" var:secret = "secret" var:jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiJiMDhmODZhZi0zNWRhLTQ4ZjItOGZhYi1jZWYzOTA0NjYwYmQifQ.-xN_h82PHVTCMA9vdoHrcZxH-x5mb11y1537t3rGzcM" decode_jwt(var:algorithm, var:secret, var:jwt) >>> {"userId"=>"b08f86af-35da-48f2-8fab-cef3904660bd"}
Transforms all characters of a string to lowercase.
downcase("BETTY") >>> betty
Returns a new date representing the end of the month.
end_of_month(10-03-19) >>> 31-03-19 00:00:00
end_of_month(10-03-19 13:41) >>> 31-03-19 23:59:59
Executes validations and returns the errors (if any) as a hash, in one go.
var:object (description is required, but blank) errors!(var:object) >>> {"description"=>[{"code"=>"is_required", "message"=>"is required", "property"=>:description}]}
`!` is the logical `NOT` Operator. Use to inverse the logical state of its operand. If a condition is true, then logical `NOT` operator will make false.
!(true) >>> false
Returns the extension of a file.
var:file = avatar.png extname(var:file) >>> png
Returns the value for a given hash and key, with an optional default in case the key does not exist for the hash.
var:answers = { "1": "answer to question 1", "2": "answer to question 2" } fetch(var:answers, "2", "Does not exist") >>> answer to question 2 fetch(var:answers, "3", "Does not exist") >>> Does not exist
Transforms a string to a float (decimal number). Only accepts `.` as a decimal delimiter.
var:text = "2.5"float(var:text) >>> 2.5 float("2,39") >>> 2.0
Returns the largest integer less than or equal to the given (decimal) value.
floor(9.2) >>> 9
floor(9.6) >>> 9
Generate a JSON Web Token.
var:algorithm = "HS256" var:secret = "secret" var:payload = "{"userId"=>"b08f86af-35da-48f2-8fab-cef3904660bd"}" generate_jwt(var:algorithm, var:secret, var:payload) >>> eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiJiMDhmODZhZi0zNWRhLTQ4ZjItOGZhYi1jZWYzOTA0NjYwYmQifQ.-xN_h82PHVTCMA9vdoHrcZxH-x5mb11y1537t3rGzcM
Generate a unique identifier following the UUID format. An example of when to use a UUID is when calling an external API via HTTP Request events, where the receiving API expects each request to have a unique identifier.
generate_uuid() >>> f384e3ad-e6dd-4cc2-b6c9-4ad5ac5b9191
Returns an IP address based on the given domain.
gethostbyname("bettyblocks.com") >>> 37.46.139.160
gethostbyname("hubspot.com") >>> 104.16.253.5
Checks if a variable can be parsed as a hash. Returns true or false.
var:hash = { "a" : "1" , "b" : "2" , "c" : "3" }hash?(var:hash) >>> true
var:no_hash = ["Betty", "Blocks"]hash?(var:no_hash) >>> false
Converts a hexadecimal string into a binary. It requires a hexadecimal string as argument and returns a binary. Often used in combination with the `base64_encode()` expression to encode payloads for web services.
hex_to_binary('82B054BD83FFAD9B6CF8BDB98CE3CC2F') >>> 10000010101100000101010010111101100000111111111110101101100110110110110011111000101111011011100110001100111000111100110000101111
Creates a `hmac_sha256` hash and requires two arguments: the string for which you want to calculate the digest and a secret key that must be included in the calculation. It is mainly used for authentication with external API connections. You can use it to create an encrypted password.
hmac_sha256("Betty Blocks", "secret") >>> ec1d3a29ae219e55fa3c3a3055a25b6ba514e0acadcb1d198798dc48dc978a66
Creates a `hmac_sha384` hash and requires two arguments: the string for which you want to calculate the digest and a secret key that must be included in the calculation. It is mainly used for authentication with external API connections. You can use it to create an encrypted password.
hmac_sha384("Betty Blocks", "secret") >>> 4b642d2c4b3ca8349714cfa4d8bed17570c94284e06e07889d9fe6b0c0c2cd9a37e91d684632803943535d149b582382
Creates a `hmac_sha512` hash and requires two arguments: the string for which you want to calculate the digest and a secret key that must be included in the calculation. It is mainly used for authentication with external API connections. You can use it to create an encrypted password.
hmac_sha512("Betty Blocks", "secret") >>> 14dd565a61c4ac3aab353edae6f81dc9225c99a90f0e138bea494c359e3ee40cbf9f581ecc57205722e8d6ed22c0748d65685e98dcd90e3264b4392d4bdbed48
Use an amount of hours in a calculation.
2019-01-04 12:00 + hours(3) >>> 2019-01-04 15:00
A boolean expression replacement for IF ELSE.
record.price < 50.00 ? record.price + 5.00 : record.price >>> If record.price is below 50 then record.price + 5.00 Else record.price
A conditional statement constructor. `ifnil` evaluates its argument and branches and checks on nil values. If a nil value applies, the default value is rendered instead.
var:value = "Betty Blocks" ifnil(var:value, "Alkmaar") = "Betty Blocks"
var:no_value = nil ifnil(var:no_value, "Alkmaar") = "Alkmaar"
Returns true if the given object is present in self.
include?(['a', 'b', 'c'], 'b') >>> true var:product = "Chocolate" var:inventory = ["Apple", "Orange", "Banana", "Pear"] include?(var:inventory, var:product) >>> false
Converts a text to an integer.
var:text = "10" 10 + int(var:text) >>> 20
Returns an array of all keys in the hash.
var:answers = { "1": "answer to question 1", "2": "answer to question 2" } keys(var:answers) >>> ["1", "2"]
Adds a specific number of whitespaces right of a text value, so the width matches the number given in the expression.
ljust("Betty", 10) >>> "Betty "
ljust("Betty", 7) >>> "Betty "
ljust("Betty", 3) >>> "Betty"
Returns a date value in the given format, based the application's locale.
var:date = 2019-03-01 locale = en-US localize(var:date, '%A %e %B %Y')) >>> Friday 1 March 2019
var:date = 2019-03-01 locale = nl-NL localize(var:date, '%A %e %B %Y')) >>> vrijdag 1 maart 2019
Returns the square of the variable in the brackets.
var:number = 10 math_sqr(var:number) >>> 100
Returns the squareroot of the variable in the brackets.
var:number = 100 math_sqrt(var:number) >>> 10
Returns the sine of the variable in the brackets.
var:number = 1 math_sin(var:number) >>> 0.841471
Returns the cosine of the variable in the brackets.
var:number = 1 math_cos(var:number) >>> 0.5403023
Returns the tangent of the variable in the brackets.
var:number = 1 math_tan(var:number) >>> 1.5574077
Returns the arcsine of the variable in the brackets.
var:number = 0.8414709848078965 math_asin(var:number) >>> 1
Returns the arcosine of the variable in the brackets.
var:number = 0.5403023058681398 math_asin(var:number) >>> 1
Returns the arctangent of the variable in the brackets.
var:number = 1.557407724654902 math_atan(var:number) >>> 1
Returns the arctangent of the two variables in the brackets.
var:number1 = 3 var:number2 = 4 math_atan2(var:number1, var:number2) >>> 0.6435011
Returns the logarithm of the variable in the brackets.
var:number = 3 math_log(var:number) >>> 1.0986123
Returns the logarithm with base 2 of the variable in the brackets.
var:number = 3 math_log2(var:number) >>> 1.5849625
Returns the logarithm with base 10 of the variable in the brackets.
var:number = 3 math_log10(var:number) >>> 0.4771213
Returns the absolute of the variable in the brackets.
var:number = -3.1415927 math_abs(var:number) >>> 3.1415927
Returns the radian number of the variable in the brackets.
var:number = 45 math_deg_to_rad(var:number) >>> 0.7853982
Returns the degrees of the variable in the brackets.
var:number = 0.7853981633974483 math_rad_to_deg(var:number) >>> 45
Returns pi.
math_pi() >>> 3.141592653589793
Returns the output of Euler by the power of given value`(x)` in the brackets. `(e^x) `
var:number = 3math_exp(var:number) >>> 20.0855369
Returns Euler.
math_e() >>> 2.718281828459045
Returns the highest number of an array of numbers.
max([1,2,3]) >>> 3
var:array = [34,29,127,45] max(var:array) >>> 127
Creates an `md5` hash of text.
md5("Betty Blocks") >> f6e8a2baa494d57bd9c8b053f1fba164
Note: We do not recommend using this expression for encryption of sensitive data. It can still be used for other, none-cryptographic purposes, though. See MD5 for more information.
Returns the lowest number of an array of numbers.
min([1,2,3]) >>> 1
var:array = [34,29,127,45] min(var:array) >>> 29
Use an amount of minutes in a calculation.
2019-01-04 12:00 + minutes(30) >>> 2019-01-04 12:30
Returns the result of matching a text value against a regex, divided in groups `( )`.
var:value = "[BB2019] Betty Blocks" var:regex = "^\[BB([0-9]*)\]([a-zA-Z\s]*)$" mmatch(var:value, var:regex, 0) >>> [BB2019] Betty Blocks
var:value = "[BB2019] Betty Blocks" var:regex = "^\[BB([0-9]*)\]([a-zA-Z\s]*)$" mmatch(var:value, var:regex, 1) >>> 2019
var:value = "[BB2019] Betty Blocks" var:regex = "^\[BB([0-9]*)\]([a-zA-Z\s]*)$" mmatch(var:value, var:regex, 2) >>> Betty Blocks
Returns the remainder after division of one number by another.
modulo(21, 5) = 1
modulo(47, 6.5) = 1.5
Rounds up the first value, so the modulus returns 0.
modulo_round(21, 5) = 25
modulo_round(10, 4) = 12
Returns the date of the monday of the given week and year
monday_of_week_number(2019, 1) >>> 2019-01-14
Returns the month from a specific date as a number expression.
month(2019-04-01) >>> 04
Use a number of months in a calculation.
2019-04-01 + months(3) >>> 2019-07-01
Inserts a `\n`, resulting in continuing on a new line.
"Hello" + newline + "World" >> Hello \n World
Checks if a fields value is empty. Returns true or false.
nil?(var:record.email) >>> true
Returns the current date and time as a date time expression.
Date = 01-04-2019 Time = 10:00:00 now >>> 2019-04-01 10:00:00
Returns the difference between given dates, in weeks.
var:date1 = 2019-04-01 var:date2 = 2019-04-22 num_weeks(var:date1, var:date2) >>> 3
Returns all numeric characters from a string.
only_numbers("a7263s11") >>> 726311
Transforms a string to a parameter, making it a URL-friendly value.
parameterize("betty blocks") >>> betty-blocks
Returns the outcome of `var:a` raised to the power of `var:b`
pow(5, 5) >>> 3125
Checks if a record or variable exists. Returns true if the record or variable exists, returns false if not.
var:record.name = "Robert" present?(var:record) >>> true
var:record.name = "Robert" present?(var.record.name) >>> true
`present?(var:record)` is exactly the same as `!(blank?(var:record))`
Returns a random number between 0 and the given number.
random(8) >>> 6
random(8) >>> 3
random(8) >>> 1
Generates a random hexadecimal string. The number argument defines the number of characters used for the string.
random_hex(6) >>> bf66d1
Returns the content of a file.
var:file = employees.csv read_file(var:file) >>> Employee ID;Name 1;Robert 2;Thomas 3;Ralph 4;Marcel 5;Jermel
Replace a certain value with a different value. You'll need this one to perform a replace on "unreadable characters" and anything with a backslash. These include newlines `(\n)`, tabs `(\t)` and carriage returns `(\r)`.
regex_replace("Betty \n Blocks", "\n", "from the") >> Betty from the Blocks
Replace a certain value with a different value.
replace("Berry Blocks", "r", "t") >> Betty Blocks
Adds a specific number of whitespaces left of a text value, so the width matches the number given in the expression.
rjust("Betty", 10) >>> " Betty"
rjust("Betty", 7) >>> " Betty"
rjust("Betty", 3) >>> "Betty"
Rounds a number with decimal to a whole number, or to a precision equal to the number given as second parameter.
round(99.8) >>> 100
round(99.876, 2) >>> 99.88
Decrypts encrypted values into plain text through a private RSA-key.
var:value = WSbb0M51xG/ygqmKoAJg44r6M3io53nTsM5Rd6WV7u4SYXEbHy+33nH4TFKBECwdVwb9NyhevCAR/1x6pLuqHvRS6hgUqh69c19PhtCF216ZjakGz0kX+87L+QX4EqHh9QEHTzkoLMMj0/WwDhqt7/8pVUJXH5UripU6o5FpXsM= var:private_key = -----BEGIN RSA PRIVATE KEY----- MIICXQIBAAKBgQCB7QOk0GzoRHG5GnYFt3IwVaaQkE0uBrF/Cp80HiemSbh+edvSiGbuZzGnoQDj+z2vq0TK+GL2IBrIlRUvyabo+cvYn3iZMmYCgmCRTsH12f+bqR4zB04YLKp/5soj/ElDE8xymrSv/ITn8VSwsOL012zEDSTgdAOtGpydWYD0wwIDAQABAoGAYSAteSfWQkvoN9fwIpXgZwGgYrF9AMtAJRhrqypfuY+iu+mcyuXtDItYM1fIsqU+l/QQmSrVz+hwHUJVdEPq4WFxqC8XsEGilk6MhNR50tUycM5I9y08WyXwklAsc4WNywMDcvdE7yvINdoERXAfl1y6L7CFP2AqLNXfZyOSgQECQQD3Swdr5ho1RfT+Aun19QCsWooufUq3WBRudXB6qKlpXsoavTlNu7mccHaI3NttWZoO2VtwEWZbaRzx5XSKCGiFAkEAhoAZGSdRNTWqRXrQeb+K67xySlZNhrRBxCpmM3Pk/kIr99A81vbBSDa2dF7r5d9DDwwR8T2ywJnTi3kjx0+OpwJBAL4W3YCSYyj6OoWbJc7b4wWZn0h3JRzkRuhVu/19cqQ9qet98vOOzvGy/VrdMorO6n5plEEEDwNLPGWxNLD6H6UCQGu/t1uVSdNMuKmMp/LA5fPQNecjmFvvkDgsl09k6vBd5odShUrYxyKo4iX73RN8dmZZjw4qFUeCdBxp4aXMMEUCQQDNO4e5HOljcyNpvvPRvmS7W6qtOyHILHiROMYHPA7Uv9EB2SpVGIYsEv5ZMZCJInYxuxNibc9EVSYTBficwY2k -----END RSA PRIVATE KEY----- var:public_key = -----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCB7QOk0GzoRHG5GnYFt3IwVaaQkE0uBrF/Cp80HiemSbh+edvSiGbuZzGnoQDj+z2vq0TK+GL2IBrIlRUvyabo+cvYn3iZMmYCgmCRTsH12f+bqR4zB04YLKp/5soj/ElDE8xymrSv/ITn8VSwsOL012zEDSTgdAOtGpydWYD0wwIDAQAB -----ENDPUBLIC KEY----- rsa_encrypt(var:value, var:public_key) >>> Betty Blocks
Encrypts values into an RSA Message through a public RSA-key.
var:value = Betty Blocks var:private_key = -----BEGIN RSA PRIVATE KEY----- MIICXQIBAAKBgQCB7QOk0GzoRHG5GnYFt3IwVaaQkE0uBrF/Cp80HiemSbh+edvSiGbuZzGnoQDj+z2vq0TK+GL2IBrIlRUvyabo+cvYn3iZMmYCgmCRTsH12f+bqR4zB04YLKp/5soj/ElDE8xymrSv/ITn8VSwsOL012zEDSTgdAOtGpydWYD0wwIDAQABAoGAYSAteSfWQkvoN9fwIpXgZwGgYrF9AMtAJRhrqypfuY+iu+mcyuXtDItYM1fIsqU+l/QQmSrVz+hwHUJVdEPq4WFxqC8XsEGilk6MhNR50tUycM5I9y08WyXwklAsc4WNywMDcvdE7yvINdoERXAfl1y6L7CFP2AqLNXfZyOSgQECQQD3Swdr5ho1RfT+Aun19QCsWooufUq3WBRudXB6qKlpXsoavTlNu7mccHaI3NttWZoO2VtwEWZbaRzx5XSKCGiFAkEAhoAZGSdRNTWqRXrQeb+K67xySlZNhrRBxCpmM3Pk/kIr99A81vbBSDa2dF7r5d9DDwwR8T2ywJnTi3kjx0+OpwJBAL4W3YCSYyj6OoWbJc7b4wWZn0h3JRzkRuhVu/19cqQ9qet98vOOzvGy/VrdMorO6n5plEEEDwNLPGWxNLD6H6UCQGu/t1uVSdNMuKmMp/LA5fPQNecjmFvvkDgsl09k6vBd5odShUrYxyKo4iX73RN8dmZZjw4qFUeCdBxp4aXMMEUCQQDNO4e5HOljcyNpvvPRvmS7W6qtOyHILHiROMYHPA7Uv9EB2SpVGIYsEv5ZMZCJInYxuxNibc9EVSYTBficwY2k -----END RSA PRIVATE KEY----- var:public_key = -----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCB7QOk0GzoRHG5GnYFt3IwVaaQkE0uBrF/Cp80HiemSbh+edvSiGbuZzGnoQDj+z2vq0TK+GL2IBrIlRUvyabo+cvYn3iZMmYCgmCRTsH12f+bqR4zB04YLKp/5soj/ElDE8xymrSv/ITn8VSwsOL012zEDSTgdAOtGpydWYD0wwIDAQAB -----END PUBLIC KEY----- rsa_encrypt(var:value, var:private_key) >>> WSbb0M51xG/ygqmKoAJg44r6M3io53nTsM5Rd6WV7u4SYXEbHy+33nH4TFKBECwdVwb9NyhevCAR/1x6pLuqHvRS6hgUqh69c19PhtCF216ZjakGz0kX+87L+QX4EqHh9QEHTzkoLMMj0/WwDhqt7/8pVUJXH5UripU6o5FpXsM=
Due to how RSA works, the text to encrypt can't be longer than the RSA-key.
For an RSA-key of 2048 bits, the text has a maximum size of 2048 / 8 => 256 characters
Returns a random object from the collection.
var:collection = ["Betty", "Blocks", "Alkmaar", "2019"] sample(var:collection) >>> "Blocks"
var:collection = ["Betty", "Blocks", "Alkmaar", "2019"] sample(var:collection) >>> "2019"
var:collection = ["Betty", "Blocks", "Alkmaar", "2019"] sample(var:collection) >>> "Betty"
Use an amount of seconds in a calculation.
2019-01-04 12:00:00 + seconds(200) >>> 2019-01-04 12:03:20
Creates a `sha1` hash of text, using the SHA-1 encryption method.
sha1("Betty Blocks") >>> b6a6208882a9ab2e097259a2534f7c126bbada4d
Creates a `sha256` hash of text, using the SHA-2 encryption method, using a 256-bit sized digest.
sha256("Betty Blocks") >>> 51588c6d5db3a3bcf1a323627f8f6839ed04bf781e5796a855719f7249e6a66c
Creates a `sha384` hash of text, using the SHA-2 encryption method, using a 384-bit sized digest.
sha384("Betty Blocks") >>> 065e413175c0d0989d94982cea6193f7a2bed7acc6a693e0e4bcebc3d1dd7db084309e015f65d231f7539b812b56bb18
Creates a `sha512` hash of text, using the SHA-2 encryption method. using a 512-bit sized digest.
sha512("Betty Blocks") >>> 619a52f61ccc91a59dbb162c4a203ca544ae02b06f81ba54cc3c055828ee747f48c911df9d9d35cef07264fcd35a610bf8fdfe141a80bb8d848e001469a6c4c0
Returns the collection in a random order.
var:collection = ["Robert", "Marcel", "Ralph", "Jermel"] shuffle(var:collection) >>> ["Jermel", "Marcel", "Robert", "Ralph"]
var:collection = ["Robert", "Marcel", "Ralph", "Jermel"] shuffle(var:collection) >>> ["Marcel", "Jermel", "Ralph", "Robert"]
var:collection = ["Robert", "Marcel", "Ralph", "Jermel"] shuffle(var:collection) >>> ["Ralph", "Jermel", "Marcel", "Robert"]
Slices an array/collection from the given start value, for the given length.
var:array = ["a", "b", "c", "d", "e", "f"] slice(var:array, 2, 3) >>> ["c", "d", "e"]
Returns an array after splitting a string on an argument/value.
split("Betty Blocks Alkmaar", " ") >>> ["Betty", "Blocks", "Alkmaar"]
Removes double whitespaces from a string.
squeeze("Betty Blocks Alkmaar") >>> Betty Blocks Alkmaar
Checks if a text value starts with the second given text value. Returns true or false.
starts_with?("Betty", "Be") >>> true
starts_with?("Blocks", "Be") >>> false
Converts a value to a string.
str(10) + str(10) >>> 1010
Creates a string based on a format applied to a datetime. Use this as a text expression.
strftime(2019-04-01T07:23:34, "%d/%m/%Y") >>> 01/04/2019
Click here for all date formats.
Some basic operators also work on strings. You can use a plus `( + )` to concatenate two strings and an asterisk/times `( * )` to repeat a string a number of times.
"Betty" * 3 >>> "BettyBettyBetty""
Betty" + "Blocks" >>> "BettyBlocks"
Transforms a string to a hash.
var:value = Betty Blocks string_to_hash(var:value) >>> { "Betty Blocks" : null }
Removes all trailing whitespaces of a string.
strip(" Betty Blocks ") >>> Betty Blocks
Returns characters from a selection of a string.
substring("Betty Blocks", 5, 11) >>> Block
Returns the sum of all the values in an array.
sum([1,2,3]) >> 6 var:collection = ["Betty","Blocks","Alkmaar"] sum(var:collection) >>> BettyBlocksAlkmaar
Returns the given timestamp in a different timezone.
var:date_time = 2019-04-01 10:20:00 time_in_timezone(var:date_time, "UTC") >> 2019-04-01 09:20:00
Transforms text to JSON format.
to_json('{[\"key\":\"123\"]}') >>> {["key" : "123"]}
Returns the current date as a date expression. If used as a date time expression, the time will be set to `00:00:00`.
Date = 2019-04-01 >>> today >>> 2019-04-01 Datetime = 2019-04-01 12:00:00 >>> today >>> 2019-04-01 00:00:00
Transliterates UTF-8 characters to `ASCII`.
transliterate("Bëtty Blöcks") >>> Betty Blocks
transliterate("Ærøskøbing") >>> AEroskobing
Shortens a string, closed by trailing text, based on the maximum number of characters. Maximum number includes the trailing text. By default, "`...`" is used as trailing text. By including a third parameter, you can choose your own trailing text.
truncate("Betty Blocks", 8) >>> Betty…
truncate("Betty Blocks", 8, "~") >>> Betty B~
Removes all double values in an array, returning only unique values.
uniq([1,2,2,3]) >>> [1,2,3]
uniq(["Betty","Blocks","Alkmaar","Blocks"]) >>> ["Betty","Blocks","Alkmaar"]
Transforms all the letters of a string to uppercase.
upcase("betty blocks") >>> BETTY BLOCKS
Checks if the record or custom model is valid.
var:employee = "employee": { "name": "", <<< REQUIRED "dob": "23-04-1994", "is_manager": false, "employee_id": 3 } valid?(var:employee) >>> false var:employee = "employee":{ "name": "Robert", <<< REQUIRED "dob": "23-04-1994", "is_manager": false, "employee_id": 3 } valid?(var:employee) >>> true
Returns a collection of all values in a hash.
var:answers = { "1": "answer to question 1", "2": "answer to question 2"} values(var:answers) >>> ["answer to question 1", "answer to question 2"]
Calculates all working days between two days. Returns an array of dates.
working_days(2019-04-01, 2019-04-09) >>> [ "2019-04-01", "2019-04-02", "2019-04-03", "2019-04-04", "2019-04-05", "2019-04-08", "2019-04-09" ] count(working_days(2019-04-01, 2019-04-09)) >>> 7
Use an amount of weeks in a calculation.
2019-05-02 + weeks(2) >>> 2019-05-16
Transforms `XML` formatted text to `JSON` formatted text.
var:xml = <document> <note> <to>Robert</to> <from>Marcel</from> <heading>Betty Blocks!</heading> <body>Wow! What a platform!</body> </note> </document> xml_to_json(var:xml) >>> { "document": { "note": { "to": "Robert", "from": "Marcel", "heading": "Betty Blocks!", "body": "Wow! What a platform!" } } }
Returns the element(s) and their values of an `XML` formatted text. If you only want the value, append `/text()` to your path.
Add `true` to the expression to ignore any other attributes (like `xmlns="value"`).
var:xml = <document xmlns:soap="http://www.w3.org/2003/05/soap-envelope/"> <note> <to>Robert</to> <from>Marcel</from> <heading>Betty Blocks!</heading> <body>Wow! What a platform!</body> </note> </document> xpath(var:xml, "/document/note/body", true) >>> <body>Wow! What a platform! </body> xpath(var:xml, "/document/note/body/text()", true) >>> Wow! What a platform!
Note: Use tools like this xpath generator if you don't want to search for the precise path you need yourself.
Returns the year from a specific date as a number expression.
year(2012-05-01) >>> 2012
Give an amount of years for usage in a calculation.
today + years(2)
In this article