Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Proofreading

The interceptor is just a record in advanced configuration options. The record name has to start with a prefix pfxInterceptor_ and then it has to continue with the actual interceptor name. Correct name is for example pfxInterceptor_myFirstExperiment.

The record cannot be empty, in such a case Unity will show you an error: “The interceptor with name pfxInterceptor_myFirstExperiment was not found”.

Basic

...

Step 1

Interceptors are written in plain JavaScript.

The main part of the interceptor are exported constants which contains contain a function.

The simplest possible example is this:

Code Block
languagejs
export const quotesDetailNew = () => {
  console.log('Test 1');
};

Code The code above will display message Test 1 at Console tab in web browser developer tools:

...

The name of the constant quotesDetailNew, determines where and when the code will be triggered. List You can find the list of possible names is in Unity under /wiki/spaces/UDEV/pages/3814555767 System Configuration / Interceptors. When you are exporting non existing name from your interceptor, for example because of a typo, Unity will display an error with unknown method names.

Each named constant can exists in two variants, one is for the PRE action with a suffix Pre and the second one for the POST action where the suffix is omitted.

...

You don't need to implement both variants. In some cases only the PRE action has a makes sense, for others it is only the POST action. TBD - Explain where to use PRE & POST

Function

...

Parameters

When Unity triggers a function which is in your exported constant, it will pass an object parameter to it. This object contains API functions and data related to the triggered action.

Code Block
languagejs
export const quotesDetailNew = (parameter) => {
  console.log(parameter);
};

The content of the passed parameter can vary. There is a common set which you get all the time. It is under key name api and it contains generic functions which you can use in all pfx Pricefx modules. If you know, that you will need api, you can use JavaScript shortcuts to obtain it.

Code Block
languagejs
export const quotesDetailNew = ({api}) => {
  api.notify.success('New quote created interceptor');
};

This example will show a green notification when a user create creates a new quote.

Or in case that you know exactly what you need you can squeeze it a little bit more.

...

If you have no clue what you get, you can always observe that parameter thru web browser developer tools by using the key word debugger.

Code Block
export const quotesDetailNew = (parameter) => {
  debugger;
};

...