# Use Rule Variables in Scripting Rules

## Define Rule Variable

Rule Variables can be defined in Rule Settings section in scripting rule editor. All you need to do is to just simply define name and value of scripting variable.

![Rule Variables editor](/files/Cu0hYa0fxF1EfDmK4dxV)

More detailed overview what you can do with Rule Variables is described [here](/doc/rules/common-rule-features/variables/rule-variables.md).

## Use Rule Variables in Scripting Rules

Usage of Rule Variables in Scripting Rules is super easy. All RVs values are stored in the`ruleVariables` object that is exposed in the script. You can use these stored values everywhere in the script (as inputs for your function or as inputs for `DR.solve()` function...)

{% hint style="danger" %}
Rule Variables supports JavaScript primitive data types only. (number, string, boolean, symbol)
{% endhint %}

```javascript
const foo = ruleVariables.foo;
const bar = ruleVariables.bar;

output.Output = `Values of Rule Variables are: ${foo} and ${bar}`;

return output;
```

## What you cant do

You cannot set `ruleVariables` from script itself or overwrite existing Rule Variable.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.decisionrules.io/doc/rules/scripting-rule/use-rule-variables-in-scripting-rules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
