Sign Up
Loading...

Variables

Watch the walkthrough

Variables

Create and use local variables within a workflow.

Recorded with an earlier Twidget interface. Names, control locations and available options may differ; use the linked documentation for current guidance.

Watch tutorial (2:40)

Browse all video tutorials

Variables are essential building blocks in Twidget that allow you to store and manipulate data dynamically within your no-code applications. They enable you to create flexible and interactive applications by holding values that can be changed and referenced throughout your workflow.

Creating Variables

To create a new variable in Twidget, you can use the Create Variable command. This will allow you to define a new variable with an initial value that you can later use and manipulate in your workflow.

Steps to Create a Variable:

  1. Open the Twidget Platform:

    Navigate to your Function, endpoint or event where you want to create the variable.

  2. Select the Create Variable Command:

    In your Add commands sidebar, find and select the Create Variable command.

  3. Define the Variable Name:

    Enter a unique name for your variable. This name will be used to reference the variable throughout your workflow.

  4. Set the Initial Value:

    Provide an initial value for your variable. This can be a number, text, boolean, or other types of data supported by Twidget.

  5. Confirm and Create:

    Confirm your settings and create the variable. The new variable will now be available for use in your builder.

Editing Existing Variables

After a variable has been created, you may need to update its value as your application runs. Twidget provides the Edit Existing Variable command to modify the value of an existing variable.

Steps to Edit an Existing Variable:

  1. Navigate to the Workflow Editor:

    Open the Add commands sidebar where your variable is located.

  2. Select the Edit Existing Variable Command:

    Choose the Edit Existing Variable command from the available options.

  3. Choose the Variable to Edit:

    Enter the variable you wish to edit

  4. Update the Value:

    Enter the new value you want to assign to the variable. This value can be dynamically calculated or statically defined based on your needs.

  5. Apply Changes:

    Confirm your changes. The variable's value will be updated and can be used in subsequent steps of your builder.

Using variables inside JSON

Choose JSON as a command value's type, then enable Resolve variables above the JSON editor. Leave it off when you want to store the JSON exactly as written. Existing saved JSON values keep this option off.

Keep placeholders inside JSON strings so the editor can validate your JSON:


{

  "name": "{{ $inputs.name }}",

  "quantity": "{{ $inputs.quantity }}",

  "customer": "{{ customer }}",

  "message": "Hello {{ $inputs.name }}",

  "items": ["{{ $inputs.items[0] }}"]

}

Use the same input or variable reference that you would choose in an Input or Variable field. For example, customer must come from an earlier command, and $inputs.quantity must be an available input.

  • When the complete string is a placeholder, its value keeps its type. A numeric quantity stays a number; a customer object stays an object. Lists, booleans and null also keep their types.

  • A placeholder inside other text produces text. Numbers, booleans and null can be included; objects and lists must use a complete placeholder instead.

  • Values inside nested objects and lists are supported. Field names stay literal.

  • Quotes and line breaks in values are handled automatically. Inserted values are not treated as another template.

  • A missing variable or invalid reference stops the command with an error. Use a validation or conditional command first when a value is optional.

References can use dots and fixed list indexes, such as $inputs.items[0].name. JavaScript, calculations, calls and variable indexes are not supported inside JSON placeholders. Calculate the value in an earlier command and reference its result instead.

In page-generated code, bare variable names that clash with browser globals are reserved. For example, use $inputs.name or a variable named customerName instead of a bare variable named name.

Workspace secrets remain available only in server-side workflows. The option is not offered for static/global values.

You can also use the Object and List editors and assign individual fields to Input or Variable.

Inserting references without typing them

In a Text, multiline text or JSON value, place the cursor where you want a reference, then click Insert variable below the editor. Search the variables and inputs available at this point in your workflow, choose one, and click Insert. Selected text is replaced; surrounding text stays unchanged.

In JSON, place the cursor inside a text value or select a complete value inside an object or list to replace. Twidget adds the required quotes and enables Resolve variables when you insert a reference. To use a variable as the entire value, choose the Variable type instead. JSON keys cannot contain dynamic references. Cancelling the picker leaves the value and its resolution setting unchanged.

The picker includes known nested object fields and list items, such as payload.customer.name and payload.items[0].sku, from declared shapes and local JSON definitions. It shows names rather than their data or secret values. Fields known only when a response arrives can still be entered manually. Static values and global/secret editors do not offer this picker.

Follow the Dynamic variables in JSON and text guide for nested picker examples, type preservation and screenshots.

Best Practices

  • Naming Conventions: Use clear and descriptive names for your variables to make your workflows easier to understand.

  • Initial Value: Always set a relevant initial value for your variables to avoid unexpected behavior.

  • Type Consistency: Ensure that values assigned to a variable are of consistent types to prevent errors during execution.

Related Topics

Output

Each function also has an optional output where you can return an output variable. To simplify the use of functions, you can define an output schema. The output schema acts as an internal documentation detailing what the output of the function will look like. This makes it easier to understand and u...

Changes

In Twidget, every modification you make in our no-code builder is meticulously documented and stored as a change. Whether you are creating an input or editing a command, each action is captured in the platform. Important: Please note changes will not go live until they are published. Viewing Changes...

Reusable Middleware

Middleware is a reusable workflow that runs before or after an endpoint, function or event. Build it once, then apply it wherever you need the same input checks, response formatting or logging. Create middleware. Open Middleware from the sidebar and choose Create Middleware. Give it a clear name, su...

Command Output

Some commands in Twidget return outputs, which are essential for dynamic and conditional logic within your workflows. These outputs are displayed next to the command and are prefixed with an "as" to indicate the variable name. Using Output Variables. Once a command returns an output, you can use the...

Publishing Changes

With Twidget's publishing feature, you can seamlessly push your changes live, ensuring that your updates take effect on the specified endpoint, function, or event. This feature also allows for version control, enabling you to revert and manage different versions of your changes effectively. Steps to...