Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

As it was described in Dynamic Interceptors , it’s possible to create interceptors through Unity UI. For a better user experience while development, we strongly recommend to use IntelliJ with PriceFX Studio plugin:

  1. Check your version of Pricefx Studio in Plugins and update the version if necessary. If the plugin is missing, install Pricefx Studio first.

     

  2. Edit the Config.js file to be able to fetch and deploy your solution to the correct environment.

     

  3. After creating a new Dynamic Interceptor on the Configuration > Interceptors page, you can fetch it. Select the Environment and Partition that you want to work with and locate your interceptor in the Advanced configuration. Then click the Fetch button.

     

  4. The procedure is similar to deploying your solution after some changes.

     

  5. After the code is deployed, use the Reload interceptor functionality.

How interceptors work

Basically, this piece of javascript code will be structured like:

export const compensationsDetailCreateNewRevision = async ({ compensationPlanOriginAPI, compensationPlanNewRevisionAPI, api: { notify }}) => {
  await notify.success('Triggered interceptor compensationsDetailCreateNewRevision');
  // TODO: Add your code
}

For each method that you would like to trigger something, there will be a function being exported. This function has one argument, which has different APIs that will offer interaction with Unity, and CLIC data manipulation. In here you can find the type definitions and documentation of all available methods and their available API through its argument. In case you struggle to find out exactly what’s available, you can run the specific interceptor method with a debugger:

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

As you may see, there are also some methods that have both the option to add PRE and POST code.

The idea behind this is that the PRE code will run before the event itself, i.e. when you have a PRE method on create new quote, this will run before the quote is created, and in case your PRE method returns false it will stop and the quote will not be created.

In case it returns something, that will be passed to Unity and can be used according to the method.

Then, the POST code will run.

PRE and POST methods have the same name, and for PRE ones they must have a Pre suffix, as in quotesDetailNew (POST) and quotesDetailNewPre (PRE).

TO BE DELETED FROM HERE


This article is not exhaustive. More content will be added later.

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 contain a function.

The simplest possible example is this:

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

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. You can find the list of possible names in Unity under 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.

export const quotesDetailNewPre = () => {
  console.log('This will be triggered before quotesDetailNew');
};

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

You don't need to implement both variants. In some cases only the PRE action 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.

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 Pricefx modules. If you know, that you will need api, you can use JavaScript shortcuts to obtain it.

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

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

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

export const quotesDetailNew = ({ api: { notify } }) => {
  notify.success("New quote created interceptor 2");
};

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.

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

  • No labels