# Javascript Formulas

GridMate provides a lightweight javascript syntax to define calculated columns on the browser side. The formulas are calculated when a grid rendered to the end user or a field is updated.

## Data Types

Currently the javascript engine supports the following data types as a return value:

* Text&#x20;
* Checkbox&#x20;
* Date&#x20;
* Number&#x20;
* Currency&#x20;
* Percent
* RichText

{% hint style="info" %}
Note that the data type is also used to customize the display for the user
{% endhint %}

## Operators

Currently the following operators are supported:

* **+**:(plus)
* **-:**(minus)
* **\***:(multiply)
* **/**:(divide)
* **%**:(Modulus)
* **<**:(less than)
* **>**::(greater than)
* **<=**:(less or equal)
* **>=**:(greater or equal)
* **&&**:(and)
* **||**:(or)
* **==**:(equal)
* **!=**:(not equal)

## Functions

### Math Functions

* **CEILING(number)** : rounds up and returns the smallest integer greater than or equal to a given number.
* **EXP(number)** : returns ***e*** raised to the power of a number.
* **FLOOR(number)** : rounds down and returns the largest integer less than or equal to a given number.
* **LN(number)** : returns the natural logarithm (base ***e***) of a number.
* **LOG(number)** : returns the base 10 logarithm of a number.
* **MAX(number, number)** : returns the largest of the numbers given as input parameters.
* **MIN(number, number)** : returns the smallest of the numbers given as input parameters.
* **ROUND(number, num\_digits)** : returns the value of a number rounded to the nearest integer.
* **SQRT(number)** : returns the square root of a number.

### Text Functions

* **BEGINS(text, compare\_text)** : determines if text begins with specific characters.
* **CONCAT(text1, text2)** : concats two arguments of text and returns the concatenated text.
* **CONTAINS(text, compare\_text)** : compares two arguments of text and returns true if the first argument contains the second argument.
* **LEFT(text, num\_chars)** : returns the specified number of characters from the beginning of a text string.
* **LEN(text)** : returns the number of characters in a specified text string.
* **LOWER(text)** : converts all letters in the specified text string to lowercase.
* **LPAD(text, padded\_length, pad\_string)** : inserts characters you specify to the left-side of a text string.
* **MID(text, start\_num, num\_chars)** : returns the specified number of characters from the middle of a text string given the starting position.
* **RIGHT(text, num\_chars)** : returns the specified number of characters from the end of a text string.
* **RPAD(text, padded\_length, pad\_string)** : inserts characters that you specify to the right-side of a text string.
* **SUBSTITUTE(text, old\_text, new\_text)** : substitutes new text for old text in a text string
* **TRIM(text)** : removes the spaces and tabs from the beginning and end of a text string.
* **UPPER(text)** : converts all letters in the specified text string to uppercase.

### Logical Functions

* **ISNULL(expression)** : determines if an expression is null.
* **NOT(logical)** : returns the inverse of the given expression.
* **OR(logical1, logical2)** : determines if expressions are true or false. Returns true if any expression is true.
* **AND(logical1, logical2)** : returns a true response if all values are true.
* **IF(logical\_test, value\_if\_true, value\_if\_false)** : determines if expressions are true or false. Returns a given value if true and another value if false.
* **CASE(expression, ​value1, result1, ...)** : checks a given expression against a series of values. If the expression is equal to a value, returns the corresponding result.

### Date Functions

* **DATEADD(date, amount, unit)**: Adds a specified time value to a date.&#x20;
* **DATEDIFF(start, end, unit)** : Returns the difference between two dates.
* **DATEVALUE(expression)** : Returns a date value for a given text expression.
* **MINUTE(date)** : Returns a minute value in the form of a number.
* **HOUR(date)** : Returns the hour value in the form of a number.
* **DAY(date)** : Returns a day of the month in the form of a number.
* **WEEKDAY(date)** : Returns the day of the week for the given date, using 1 for Sunday, 2 for Monday, through 7 for Saturday
* **MONTH(date)** : Returns the month, a number from 1 (January) through 12 (December) in number format of a given date
* **YEAR(date) :** Returns a year of the date in the form of a number
* **TODAY()** : Returns the current date as a date data type
* **NOW()** : Returns a date/time representing the current moment

{% hint style="info" %}
Unit can be "minute", "hour", "day", "month" or "year".&#x20;
{% endhint %}

### Other Functions

* **APEX(handler, param1, value1, ...)** :  Call an Apex class and return its value.&#x20;


---

# 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.gridmate.io/package-reference/javascript-formulas.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.
