How to create an interceptor through Unity
Before all, please make sure you have Administration > Develop Interceptors role activated. It’s also important to mention that dynamic interceptors are not compatible with Ember Unity parts.
After that, you will be able to navigate to Interceptors page, which can be found on Configuration Page, under CRM Integration section.
As you open Interceptors page, you will see the Set Interceptor button, which will display a modal where you can create an interceptor. Please note that all interceptors have pfxInterceptor_ as prefix, which will be used when saving them as a Advanced Configuration record. You can also set the interceptor as temporary, which means that the given interceptor will be attached
...
Table of Contents | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Anchor | ||||
---|---|---|---|---|
|
Info |
---|
Available from version 14.0 |
You can edit Interceptor's code directly from Pricefx.
Go to Administration > Configuration > CRM Integration > Interceptors.
Click Edit interceptor.
The window with the code of the currently Active interceptor will appear.
...
How to Add Interceptor Method Template in Pricefx
Prerequisites:
Make sure you have the Develop Interceptors role assigned.
You have crated Interceptor, and it’s assigned to CRM config.
Steps to edit an Interceptor:
In Configuration > Interceptors you will see all available intercepted methods. Each method refers to an event in
...
Pricefx Interceptor Methods. Some of these events are:
quotesDetailNewCheck
This method is triggered after clicking the
...
New button at /#/qc/quotes, but before the Quote is created. If this method returns false,
...
the Quote will not be created and the user will stay at the Quote list. In this method you
...
do not have access to quoteAPI, but you can use other
...
APIs for checking conditions from CRMs.
quotesDetailNew
The starting point for this event is clicking the New button at /#/qc/quotes. The method is triggered after the new Quote is recalculated and saved at backend and the user is redirected to the Quote detail page /#/qc/quotes/<quoteId>.quotesDetailEdit
Triggered when a user opens the Quote detail page.quotesDetailRecalculate
Triggered when a user clicks the Recalculate button on the Quote detail page /#/qc/quotes/<quoteId>.quotesDetailSubmit
Triggered when a user clicks the OK button in the Submit modal dialog on the Quote detail page /#/qc/quotes/<quoteId> after clicking Submit.quotesDetailTabSwitch
Triggered at Quote detail at open and then when the user switches to a different tab.
...
To see a regularly updated list of all available methods and when they are triggered,
...
visit interceptor Method Names.
As you expand one of the method fields, you will see Add PRE Code, and/or Add POST Code buttons (according to each method’s compatibility):
When clicking
...
any of them, a modal window will show
...
:
...
...
There is a dropdown
...
menu with available templates, and you can also paste your
...
JavaScript code in there.
More technical explanations about how this code is structured and what PRE and POST means are available by the end of this article.
Reload the interceptor every time after modifying the interceptor to apply changes.
Finally, you can test
...
the interceptor's functionality, in this case
...
by creating a new quote:
...
How to
...
Edit Interceptor in VSCode or VSCodium
Prerequisites: Make sure you have the Develop Interceptors role assigned.
For a better user experience while during development, we strongly recommend to use IntelliJ with PriceFX Studio plugin. After making sure you have the permissions as mentioned aboveusing VSCode with the Pricefx Code extension as IntelliJ offers JavaScript code highlighting only in paid versions of the IDE.
Install and login to the partition in which you want to edit interceptor. Here's how to get it done Pricefx Code.
Open the interceptor you would like to edit.
Save the file after editing is done. A notification should appear and inform that the interceptor was saved.
Reload the interceptor every time after modifying the interceptor to apply changes.
How to Edit Interceptor in IntelliJ
Prerequisites: Make sure you have the Develop Interceptors and General Admin role assigned.
Steps to edit an Interceptor:
Check your version of Pricefx Studio in Plugins and update the version if necessary. If the plugin is missing, install Pricefx Studio first.
Edit the Config.js file to be able to fetch and deploy your solution to the correct environment.
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.
The procedure is similar to deploying your solution after some changes.
After the code is deployed, use the Reload interceptor functionality.
How to create an interceptor through VSCode or VSCodium
IntelliJ offers JavaScript code highlighting only in paid versions of the IDE. As an alternative, for VSCode and VSCodium we have developed Pricefx Code extension, which offers Interceptor and Configuration file editing. Extension works only with permissions which are mentioned above.
All information regarding Pricefx Code can be found here: Pricefx Code.
How interceptors work
Basically, this piece of javascript code will be structured like:
Code Block |
---|
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:
Code Block |
---|
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 intercepted method, 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.
...
Interceptor functionality.