Expressions and code
Define reusable variables in Duaer
Duaer variables store a value for more than one digital organization. Expressions and the Code node read them as $vars.key. Every variable is a string, and a run only reads it.
What a Duaer variable is
A Duaer variable is not a const you declare in JavaScript for one run. It is a key and value stored for the instance or a project, so more than one digital organization can read it. When an expression or a Code node runs, Duaer replaces $vars.key with the value at that time.
Every value is a string. A missing value reads as undefined, and the run does not fail because of that. A run cannot change a variable. Change it on the Variables screen. To store data for one run, use custom execution data, not a variable.
Who can create one, and how global differs from project
Open Variables. The instance owner can create variables. Whether you can create one inside a project depends on your role there. If the current plan does not include variables, the screen tells you to upgrade.
A global variable is readable across the instance. A project variable is readable only in that project’s digital organizations. When both use the same key, the project variable overrides the global one.
Create or change a variable
- On Variables, select Add variable.
- Enter a Key and a Value. A key is at most 50 characters. A value is at most 1000 characters.
- A new key may use letters, numbers, and underscores, and it cannot start with a number. A leading number breaks the $vars.key dot form.
- When you create from the overview, choose Scope. Global is the whole instance. Project is one project. Creating from a project page sets the scope to that project.
- Select Save. To change or remove one, hover the row and select Edit or Delete.
Read it in an expression or a Code node
The first line is an expression in a node parameter. The second line is a JavaScript Code node. The key is the Key you saved.
{{ $vars.api_host }}
$vars.api_hostQuestions
How do you read a Duaer variable in an expression?
In Duaer, a variable is $vars.key. An expression puts that inside {{ }}. A JavaScript Code node writes $vars.key directly. Every value is a string. A missing key reads as undefined, and the run does not fail because of that.
Which Duaer variable wins when a global key and a project key match?
A Duaer global variable is readable across the instance. A project variable is readable only in that project’s digital organizations. When both use the same key, the project variable overrides the global one. A run cannot change a variable. Change it on the Variables screen.
In this section
Write expressions in Duaer
A Duaer expression sits inside {{ }} and reads the current item, earlier nodes, and variables from a node parameter. When you are only reshaping fields, prepare them in an Edit Fields (Set) node first.
ExpressionsBuilt-in methods and variables in Duaer expressions
Duaer expressions provide variables for reading data and methods you call on a value. The Code node runs plain JavaScript and native Luxon. A method that is a Duaer extension may be missing there, or take different arguments.
ExpressionsConvenience methods in Duaer expressions
Duaer expressions use $json for the current item, $("Node name") for an earlier node, and $now and $if() for time and conditions. These names are available in expression mode on a parameter.
ExpressionsVariables for HTTP node pagination
The Duaer HTTP Request node provides $pageCount, $request, and $response in pagination expressions. Those three names work only in that node. Other nodes cannot read them.
TransformData transformation methods by type
Duaer expressions call transformation methods on a value, such as {{ $json.name.toTitleCase() }}. The methods are grouped by array, boolean, date, number, object, and string. The Code node does not have these extensions.
TransformArray transformation methods
In a Duaer expression, call an array method on the array, such as {{ $json.ids.unique() }}. average, max, and min throw if any element is not a number.
TransformBoolean transformation methods
In a Duaer expression, a boolean can be tested for empty and converted to a number or a string. true becomes 1 as a number. false becomes 0.
TransformDate transformation methods
In a Duaer expression, $now and $today are Luxon DateTime values. Call toDateTime() on a string or number before format, plus, or setZone.
TransformNumber transformation methods
In a Duaer expression, number methods round, test even or odd, and convert to a boolean, a string, or a DateTime. round goes to the nearest number. ceil goes up. floor goes down.
TransformObject transformation methods
In a Duaer expression, object methods test fields, drop fields, merge objects, and encode an object as a query string. keys() and values() return the field names and the values.
TransformString transformation methods
In a Duaer expression, string methods change case, slice text, test emails and URLs, and encode or decode base64 and URLs. Call the method on the string.
QueryQuery JSON with JMESPath
Duaer queries JSON with $jmespath(object, "query"). Expressions and the JavaScript Code node can call it. The Python Code node does not have this function.
DatesUse Luxon for dates in expressions
Dates in a Duaer expression are Luxon DateTime values. $now and $today are DateTime values already. The Code node uses native Luxon. format() and plus(amount, unit) do not carry over unchanged.
ExamplesDuaer expression examples
These examples run in Duaer expression mode. They read the current item, fill a default, format a date, and move a large reshape into Edit Fields (Set).
ExamplesMethods and variables reference
These are the names used most often in a Duaer expression. The current item is $json, an earlier node is $("Node name"), variables are $vars, and transformation methods are grouped by data type.