How to Write Interceptors

This is a sequel to https://pricefx.atlassian.net/wiki/spaces/KB/pages/4120281261. Please read the previous part first before moving on.

This is a step-by-step guide on how to start writing interceptors.

How to Choose and Use Interceptor Method

All interceptor method names follow a simple naming structure. For example, let's break down the name quotesDetailCreateNewRevision and understand when this method will be called. Quotes indicates that this function will be triggered on a quote page module. Detail implies that it will be triggered on a single selected or opened quote. Meanwhile, quote list would be triggered only on the list. Lastly, CreateNewRevision suggests that the interceptor will be triggered when a new revision will be created.

Here you can find all available interceptor Method Names.

How to Use Interceptor Methods

On the top level of the JS file, you can declare multiple interceptor methods.

Interceptor Method Parameters

With a parameter you can make a query in a CRM system, call notification in Unity, etc. Parameters are an essential part of the Interceptors.

What Parameters Does the Interceptor Method Have?

Every interceptor has its own unique set of parameters, but there is a logic behind understanding what parameters you can expect to find in different interceptor methods.

api: is a common parameter for all interceptor methods, InterceptorMethodAPI.

quoteAPI: is only available in the Quoting module.

compensationPlanAPI: is only available in the Sales Compensations module.

contractAPI: is only available in the Agreements & Promotions module.

rebateAgreementAPI: is only available in the Rebates module.

opportunityId: is available in methods with action OpportunityAssign.

accountId: is available in methods with action AccountAssign.

filter: is available in methods with action that contains word filter, for example action: FilterAdd.

For more details about the parameters that each method has, you can refer to the interceptor Method Names.

More About API Parameter

In api parameter, the most commonly used functions are:

crmManager: InterceptorMethodAPI | crmManager allows you to access CRM system, but it is only available inside CRM system.
notify: InterceptorMethodAPI | notify is used for calling notification.
navigate: InterceptorMethodAPI | navigate with this function, you can navigate to other pages or even create new quote with selected type.

This is not all you can do with api. Explore InterceptorMethodAPI and find more functions that you can call from api.

Use ‘await' or 'then’ When Accessing API or QuoteAPI Parameters from Interceptor Methods

If you do not use await or then with api, quoteAPI, or other parameters, they will not yield any results, as all parameters within Interceptor Methods are Promises.

Incorrect

export const quotesDetailSubmitPre = async ({ api: { crmManager } }) => { const payload = crmManager.getPayload() console.log(payload) // returns {Promise pending} }

Correct

export const quotesDetailSubmitPre = async ({ api: { crmManager } }) => { const payload = await crmManager.getPayload() console.log(payload) // returns {id: '123', name: 'pricefx Pivo a Párek' ...} }

How to Get Data from CRM and Pricefx

From CRM

To get data from a CRM, Pricefx should be placed into CRM system. Currently, Pricefx doesn’t have any possibility to access CRM system data outside the CRM.

Payload

export const quotesDetailSubmitPre = async ({ api: { crmManager } }) => { const payload = await crmManager.getPayload(); console.log(payload); };

Returns data from the current CRM page. For example: if getPayload is triggered under account page in Salesforce, getPayload will return all data from that specific account: accountId, accountName and etc.

Setting Fields in Pricefx

To populate value/result for inputs in Pricefx with interceptor is fairly easy to do. You can change both inputs and outputs values in Pricefx modules.

To do so, you will need to:

  1. Choose interceptor method which has scope detail.

  2. Add to parameters module API, for example: quoteAPI, compensationPlanAPI or …

  3. Inside function write await *module*API.setHeaderValue('label', 'pricefx Pivo a Párek');. This function will set value in header, but there are also functions for setting header input value, output result and line items inputs.

Full code example:

For more information regarding CLIC Interceptor API, you can find here: ClicInterceptorAPI

Don't Reinvent the Wheel!

In most cases, Interceptor is used for field population or for showing notification message. For those cases we have prepared templates which are available in Interceptor Methods. Additionally, you can locate these templates in Unity application by navigating to Configuration > Interceptors.

Found an issue in documentation? Write to us.