# Dynamic Script

You can write a script (a new language that Apxor has created which somewhat looks like Javascript) instead of plain text to substitute user and session properties that you have already logged to Apxor SDK or you can substitute a text element from your application, or hidden text that you set it as a keyed tag (apx\_view\_tag).

#### The Apxor Language <a href="#the-apxor-language" id="the-apxor-language"></a>

The Apxor language looks similar to Javascript with some modifications.

We assume every dynamic param that you want to substitute in a text is a pre-defined variable that you can create upfront in the Script dialogue that Apxor Dashboard provides to you.

We support the following operators and keywords as part of our language specification

**Unary Operators**

> `!` (Negation)

**Logical Operators**

> `&&` (Logical AND)
>
> `||` (Logical OR)

**Mathematical Operators**

> `+` (Arithmetic Addition)
>
> `-` (Arithmetic Subtraction)
>
> `*` (Arithmetic Multiplication)
>
> `/` (Arithmetic Division)
>
> `%` (Arithmetic Modulo)

**Comparison Operators**

> `<` (Less than)
>
> `<=` (Less than or Equals)
>
> `>` (Greater than)
>
> `>=` (Greater than or Equals)
>
> `==` (Equality)
>
> `!=` (Not Equality)
>
> `contains` (Checks if a string contains another string)

**Keywords**

> `httpGet`, `onSuccess`, `onError` will be used to make a HTTP GET API call
>
> `format` will be used to format a string
>
> `if`, `else` will be used to write conditional evaluation
>
> `true`, `false` boolean keywords
>
> `toInt` will be helful to convert double/float values to integer

**Examples**

> **Note:**
>
> Assume the following variables are defined
>
> * UserName (User Property)
> * RewardPoints (User Property)
> * IsSubscribed (User Property)
> * Subscribed (API JSON response parameter `user.is_subscribed`)

* Simple formatting of the string

```javascript
format(
  "Hello {}. We are excited to give you {} reward points. You can see these points in the Rewards section:",
  UserName,
  toInt(RewardPoints)
);
```

* Conditional Dynamic Text

```javascript
if (!IsSubscribed && RewardPoints < 500) {
  format(
    "Hello {}, you are just {} points away to get free subscription",
    UserName,
    500 - RewardPoints
  )
} else {
  format("Hello {}, You are already subscribed", UserName)
}
```

* API call

```javascript
httpGet(format("https://your-server.com/your-api?userName={}", UserName))
  .onSuccess(() => {
    if (SubScribed) {
      format("Hello {}, you are already subscribed", UserName)
    } else {
      format("Hello {}, you are not subscribed yet", UserName)
    }
  })
  .onError(() => format("Something went wrong. Try again later"));
```


---

# 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://guides.apxor.com/product-guides/dynamic-script.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.
