> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rwsintegration.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

> Learn how to use business rules to transform and filter data in RWS Integration

Business rules are JavaScript functions that allow you to perform transformations and filters on data during the integration.

<CardGroup cols={2}>
  <Card title="Transform data" icon="arrow-right-arrow-left" href="/en/features/business-rules/transform">
    Modify or combine values
  </Card>

  <Card title="Filter data" icon="filter" href="/en/features/business-rules/filter">
    Remove data from the integration
  </Card>
</CardGroup>

## Business rule structure

Every business rule is a JavaScript arrow function that receives a parameter and returns a value.

```javascript theme={null}
(context) => {
  // your logic here
  // returns transformed value
};
```

The `context` contains the current data being processed, and the function returns a value that can be used in the integration.

### Object reference

| Properties  | Contains                              | Access                                                 |
| ----------- | ------------------------------------- | ------------------------------------------------------ |
| datapoint   | Current record being processed        | `context.datapoint`                                    |
| enrichments | Each enrichment response, by its name | `context.{{ enrichmentName }}.{{ completeFieldPath }}` |
| params      | Parameters used in Extraction         | `context.params`                                       |

## Reusable rule

In RWS Integration it is possible to reuse an existing rule.

### When to use

* When the same logic is used in multiple rules
* To encapsulate very complex logic

### How it works

You can use the `BusinessRule.transform` function to call an existing rule, it works with the following parameters:

| Parameter | Description                                            |
| --------- | ------------------------------------------------------ |
| tenantId  | The ID of the tenant where the rule should be executed |
| ruleId    | The ID of the business rule to be called               |
| object    | The object data that the other rule should use         |

### Example

To create a reusable rule for price formatting and call it from other rules:

**Price Formatting Rule (ID: `67f51e19c8a10ceefa121cd2`):**

```javascript theme={null}
(context) => {
  const price = new Decimal(context.datapoint.price);
  return price.toFixed(2);
};
```

**Product Rule (calls the formatter):**

```javascript theme={null}
(context) => {
  const formattedPrice = await BusinessRule.transform(
    'yourTenant',
    '67f51e19c8a10ceefa121cd2',
    context
  );

  return {
    name: context.datapoint.name,
    price: formattedPrice
  };
}
```

## Auxiliary libraries

RWS provides several JavaScript libraries that you can use in your business rules

| Library   | How to use                       | Documentation                                                                |
| --------- | -------------------------------- | ---------------------------------------------------------------------------- |
| Lodash    | Global variable `_` (underscore) | [Lodash documentation](https://lodash.com/docs/4.17.15)                      |
| Dayjs     | Global variable `dayjs`          | [Day.js documentation](https://day.js.org/docs/en/installation/installation) |
| Decimaljs | Global variable `Decimal`        | [Decimal.js documentation](https://mikemcl.github.io/decimal.js/)            |
