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

Transform data

Modify or combine values

Filter data

Remove data from the integration

Business rule structure

Every business rule is a JavaScript arrow function that receives a parameter and returns a value.
(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

PropertiesContainsAccess
objectCurrent unit of data being processedcontext.object
resourcesEnrichment responsecontext.resources.{{enrichmentName}}.{{completeFieldPath}}
paramsParameters used in Extractioncontext.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:
ParameterDescription
tenantIdThe ID of the tenant where the rule should be executed
ruleIdThe ID of the business rule to be called
objectThe 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):
(context) => {
  const price = new Decimal(context.object.price);
  return price.toFixed(2);
};
Product Rule (calls the formatter):
(context) => {
  const formattedPrice = await BusinessRule.transform(
    'yourTenant',
    '67f51e19c8a10ceefa121cd2',
    context
  );

  return {
    name: context.object.name,
    price: formattedPrice
  };
}

Auxiliary libraries

RWS provides several JavaScript libraries that you can use in your business rules
LibraryHow to useDocumentation
LodashGlobal variable _ (underscore)Lodash documentation
DayjsGlobal variable dayjsDay.js documentation
DecimaljsGlobal variable DecimalDecimal.js documentation