Variables in Penbox forms allow you to define and manipulate values dynamically within a form. Unlike form elements (such as input fields), variables exist independently and are often used for calculations, conditions, and logic-based outputs.

These variables can leverage Penscript operations, such as :if, :else, or :sum, to perform calculations, control logic, and support multi-language outputs.

Defining Variables

Variables can be structured in groups or as standalone values:

{
  "group_of_variables": {
    "variable_1": "static",
    "variable_2": "{data.input1 + data.input2}"
  },
  "standalone_variable": "static_variable"
}
  • variable_1: A static variable that always holds a fixed value.
  • variable_2: A computed variable that dynamically adds two inputs (input1 and input2).

Using Variables in the Form

You can use the variable anywhere in your form to reference it.

That will render:


Supported Variable Types and Operations

1. Static Variables

A static variable is assigned a fixed value and does not change based on user input.

{
  "static_variable": "Penbox"
}

📌 Use Case: Storing a default label or constant value.


2. Computed Variables

A computed variable uses data inputs and expressions to determine its value.

{
  "computed_variable": "{data.age * 2}"
}

3. Conditional Logic (:if, :else)

Penbox allows conditional expressions using :if and :else. See Penscript Logic for more details

Example: Assigning a Risk Profile Based on Points

{
  "profile_type": {
    ":if": {
      ":increasing": [
        "{profile_points}",
        30
      ]
    },
    ":else": {
      ":if": {
        ":increasing": [
          30,
          "{profile_points}",
          50
        ]
      },
      ":else": {
        ":if": {
          ":increasing": [
            50,
            "{profile_points}"
          ]
        },
        ":then": {
          ":i18n": {
            "fr": "Vous êtes un investisseur dynamique.",
            "nl": "U bent een dynamische belegger."
          }
        }
      },
      ":then": {
        ":i18n": {
          "fr": "Vous êtes un investisseur équilibré.",
          "nl": "U bent een evenwichtige belegger."
        }
      }
    },
    ":then": {
      ":i18n": {
        "fr": "Vous êtes un investisseur prudent.",
        "nl": "U bent een voorzichtige investeerder."
      }
    }
  }
}

Explanation

  • If profile_points ≤ 30 → Assign “Prudent Investor.”
  • If profile_points between 30 and 50 → Assign “Balanced Investor.”
  • If profile_points ≥ 50 → Assign “Dynamic Investor.”

📌 Use Case: Risk profiling in financial assessments.


4. Summation (:sum)

The :sum operation allows adding multiple values together.

Example: Calculating Total Profile Points

{
  "profile_points": {
    ":sum": [
      "{data.profile_age}",
      "{data.profile_education}",
      "{data.profile_assets}",
      "{data.profile_revenues}",
      "{data.profile_transactions}",
      "{data.profile_duration}",
      "{data.profile_reaction_unpredicted}",
      "{data.profile_main_objective}",
      "{data.profile_reaction_lost}",
      "{data.profile_volatility}",
      "{data.profile_losts_accepted}",
      "{data.profile_investment_split}",
      "{data.profile_portofolio_choice}"
    ]
  }
}

📌 Use Case: Aggregating different aspects of a user’s profile into a single score.


Comprehensive Example: Full Dynamic Profile Calculation

Below is a complete example integrating computed variables, summation, conditional logic, and multi-language support.

{
  "profile_points": {
    ":sum": [
      "{data.profile_age}",
      "{data.profile_education}",
      "{data.profile_assets}"
    ]
  },
  "profile_type": {
    ":if": {
      ":increasing": [
        "{profile_points}",
        30
      ]
    },
    ":else": {
      ":if": {
        ":increasing": [
          30,
          "{profile_points}",
          50
        ]
      },
      ":else": {
        ":if": {
          ":increasing": [
            50,
            "{profile_points}"
          ]
        },
        ":then": {
          ":i18n": {
            "fr": "Vous êtes un investisseur dynamique.",
            "nl": "U bent een dynamische belegger."
          }
        }
      },
      ":then": {
        ":i18n": {
          "fr": "Vous êtes un investisseur équilibré.",
          "nl": "U bent een evenwichtige belegger."
        }
      }
    },
    ":then": {
      ":i18n": {
        "fr": "Vous êtes un investisseur prudent.",
        "nl": "U bent een voorzichtige investeerder."
      }
    }
  }
}

📝 How It Works

  1. The profile_points variable calculates a total score based on input data.
  2. The profile_type variable categorizes users based on their points:
  • ≤ 30 → “Prudent Investor”
  • 30 - 50 → “Balanced Investor”
  • ≥ 50 → “Dynamic Investor”
  1. Multi-language labels ensure correct display based on user preferences.

Key Takeaways

  • Variables can be static or computed using data from form inputs.
  • Penscript operations (:if, :sum, :increasing) enable complex logic for dynamic forms.
  • Multi-language support (:i18n) ensures accessibility in different languages.
  • Grouping variables helps organize form logic for better readability.

📌 Use Case Scenarios

  • Automated risk profiling based on user inputs.
  • Dynamic scoring systems for eligibility checks.
  • Multi-language personalized messages in forms.

👀

By leveraging Penscript operations, Penbox forms can become more dynamic, personalized, and automated!