Create an external connection
Create an external connection in ServiceNow CPQ to enable enrichments to retrieve data from an external system for use in configuration rules.
Before you begin
Role required: admin
About this task
External connections are used in configuration rules only. They can only be called from an enrichment script. After you configure an external connection, reference it in your enrichment script using External.*connectionName*(inputs), where connectionName is the unique name of the connection.
External Connections list view in CPQ Administration
Note: To call an external system from a transaction rule instead, add a connection. For more information, see Create a connection for ServiceNow Quote Experience calls.
Procedure
Navigate to All > CPQ Administration > Utilities > External Connections.
Select +New to create a new external connection.
In the Authentication type field, select the credential method that the external system requires, then complete the fields for that authentication type.
| Authentication type | Action |
|---|---|
| No authentication | No additional fields are required. The external connection calls the API without credentials. |
| Bearer token | In the Authentication token field, enter the bearer token provided by the external service. |
| OAuth - Client credentials flow | Complete the following fields:- Client ID: Client identifier created for ServiceNow CPQ with the authorization server. - Client secret: Tokenized reference to the client secret. The actual value is stored in the GCP secret store. In development environments, the value is stored directly. - Token URL: URL of the authorization server where ServiceNow CPQ exchanges the client ID and secret for an access token. - Scope: Scopes to include in the token request. This field is available only when OAuth - Client credentials flow is selected in the Authentication type field. |
In the Path field, enter the path to append to the host URL, including any parameter variables for dynamic segments.
Use double curly braces to define a parameter variable in the path. For example:
/v4/latest/{{inputVariable}}In your enrichment script, pass the variable as a key-value pair in the inputs object and wrap the value in
encodeURIComponent()to ensure the value is URL-safe:let inputs = {"inputVariable": encodeURIComponent(cfgRequest.baseCurrency.value)}; let results = External.exchangeRatesAPI(inputs);In the Timeout field, enter the maximum time in milliseconds that ServiceNow CPQ waits for a response from the external system.
Start with 500 milliseconds. If the external connection regularly exceeds this limit, increase the value, keeping in mind that higher timeouts may slow the end-user configuration experience.
Select Save.
Result
The external connection is saved and available to call from enrichment scripts.
BOM enrichment using an external pricing connection
The following on-BOM-response enrichment calls a powerPricing external connection to retrieve customer-specific rate data and apply it to ProductList records. The connection accepts two input variables — membershipCode and icp — and returns a pricing response that the script uses to set prices on individual products.
var powerInputs = {"membershipCode": cfg.eCMembershipCode, "icp": cfg.eCICPNumber};
let powerResponse = External.powerPricing(powerInputs);
let dailyCharge = 0;
let ratesArr = [];
if (powerResponse.status == 200) {
for (var record of powerResponse.body) {
if (record.chargeType == cfg.expectedUsage) {
dailyCharge = record.dailyCharges;
ratesArr = record.rates;
}
}
for (var prod of ProductList) {
if (prod.id == "electricBillEstimator") {
let addedPrice = dailyCharge * cfg.serviceDurationInDays;
prod.price = addedPrice;
}
if (prod.id == "Standard Rate" || prod.id == "Low Rate") {
prod.price = dailyCharge;
}
}
for (var rateVal of ratesArr) {
ProductList.id = "Additional Charge Per KWH: " + rateVal.name;
ProductList.quantity = 1;
ProductList.bomType = "Manufacturing";
ProductList.orderNumber = 2;
ProductList.price = rateVal.rate;
ProductList.notes = rateVal.measure;
ProductList.parentProduct = "electricBillEstimator";
ProductList.next();
}
}
return ProductList;
Related topics