> For the complete documentation index, see [llms.txt](https://docs.decisionrules.io/doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decisionrules.io/doc/v1/scripting-rules/use-rule-variables-in-scripting-rules.md).

# Use Rule Variables in Scripting Rules

This page contains an simple tutorial how to implement Rule Variables into your Scripting rule script.

## 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](https://content.gitbook.com/content/dv9UprVu3KjO5la255ws/blobs/uf1SEL9l0MvLET68eovf/image.png)

More detailed overview what you can do with Rule Variables is described [here](/doc/v1/other/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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
