📖
Rulecube documentation
v2.4
v2.4
  • Overview
  • Quick Start
  • Tutorial
    • Getting started
    • Create and Run Your First Ruleset
    • Use Constants and Methods
    • Create and Call Functions
    • Adding Testcases
    • Using Lookup Tables
    • Using Entities
    • Using Forms
  • How-to Guides
    • Logging in and Authorization
      • Activate Your Account From an Invitation
      • Log in to Rulecube
      • Change Your Password
      • Recover Your Password
      • Two-factor authentication (2FA)
      • Invite Other Users to Rulecube
      • Edit a User's Role
      • Delete a User
    • Ruleset Development
      • Create a Ruleset
      • Set the Input for a Ruleset
      • Create a Rule
      • Generate Alerts
      • Try out a Ruleset
      • Call a Ruleset from Your Software
      • Entities
        • Create an Entity
        • Drag and Drop a JSON Schema or XSD to create entities
        • Entity instantiation
        • Persisted Entities
      • Constants
        • Constant Tables
      • Functions
      • Built-in Functions
      • Create and Run a Testcase
      • Delete a Ruleset or Components
      • Debugging your Ruleset
    • Create a Workflow
      • Workflow step types
      • Working with documents in a workflow
    • Work with (Environment) Variables
    • Call a Ruleset via Its API From Postman
    • Creating input from JSON Schema
    • Use a Ruleset from Your Software
    • Ruleset Productivity Tips
    • Create an Ockto workflow
    • Alert aggregation
    • Forms
      • Introduction and overview
      • Create a Data table
  • Language Reference
    • Global
    • Array
    • Compression
    • Crypto
    • Date
    • Encryption (deprecated)
    • Finance
    • Http
    • Mail
    • MongoDB
    • Ockto
    • PDF
    • SQL
    • Statistics
    • System
    • UserStore
    • Workflow
Powered by GitBook
On this page
  • Introduction
  • Procedure
  • Additional resources
  1. How-to Guides
  2. Ruleset Development

Functions

PreviousConstant TablesNextBuilt-in Functions

Introduction

This guide explains how to create and use functions in rulesets.

Functions are a set of statements that perform a task or calculate a value and are useful to combine some functionality that you use multiple times in your ruleset. Functions are comparable to JavaScript functions, and you can create them yourself in Rulecube and use them anywhere you need their functionality.

Just one bit of info before you start creating a function. Functions need input to operate on, and an input for a function is called a parameter. So when calling a function, you supply its parameters, and the function returns a calculated or determined result.

Procedure

Let's say you're developing a ruleset that determines lending risks, and you need to calculate the so-called debt-to-income (DTI) ratio at several places. The DTI ratio is a person's monthly debt payments divided by the gross monthly income. You can add this calculation anywhere you need, but it's much more efficient if you create a function for this and call it when needed.

  1. Create a ruleset named RiskAssessment.

  2. Create a function named DTI, and in the Return type list, select number.

  3. Click Add parameter. ↳ Rulecube adds a parameter row:

  4. In the Name field, enter monthlyDebtPayments, and in the Type list, select number.

  5. Add a second parameter named grossMonthlyIncome, and also set its Type to number.

  6. In the Function body, enter the following function:

    monthlyDebtPayments / grossMonthlyIncome * 100

    Explanation In general, the DTI is calculated as a percentage as in this calculation.

  7. Click Save. ↳ The DTI function is now ready to be called by its name, providing the required parameters. For example, from a rule Expression with Payments and Income as ruleset inputs which you supply as parameters:

    DTI(Payments, Income)

Additional resources

  • You can combine your functions into one ruleset and designate this ruleset as a library. This way, you enable your functions to be called from any ruleset: Reference Guide: Libraries.

Rulecube has a list of built-in functions called methods: How-to Guide: .

Use Methods