CPQ scripting language reference

  • Release version: Australia
  • Updated March 12, 2026
  • 3 minutes to read
  • Summarize
    Summarized using AI
    This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.

    Summary of CPQ scripting language reference

    The CPQ scripting language in ServiceNow CPQ Australia release (updated March 12, 2026) is a JavaScript-like language designed to dynamically modify field values and BOM data through rules and enrichments during product configuration. While it does not support the full complexity of JavaScript, it provides a robust set of operators, objects, and keywords to enable flexible scripting for CPQ configurations. The scripting capabilities continue to evolve, so customers should check for the latest features.

    Show full answer Show less

    Supported Operators, Objects, and Keywords

    • Operators: Arithmetic (+, -, , /, %, ++, --), String concatenation (+, +=), Assignment (=, +=, -=), Comparison (==, ===, !=, !==, >, <, >=, <=), and Logical (&&, ||)
    • Objects: Arrays, Strings, Numbers, Booleans, Maps, and Dates (manipulable but not returnable). Unsupported: undefined, NaN, null
    • Keywords: var, let, const, new, if, else if, else, for, for/of, return

    Note: While loops (while) and unconditional for loops with break are unsupported to avoid infinite loops. Functions are not supported; scripts should be concise, ideally one function. For complex logic, use managed tables and table queries.

    Workarounds and Type Handling

    • Unsupported operations: Use explicit multiplication/division assignments instead of shorthand (e.g., number = number otherNumber;) and Math.pow(x, y) for exponentiation.
    • Type conversion: Convert arrays to strings using Array.toString(), numbers to strings by concatenation with "", and numeric strings to numbers by subtracting zero.
    • Type checking: Use LGK.isNumber(value) to verify numeric types.

    Accessing Object Properties

    Properties of map objects such as cfgRequest can be accessed using dot notation (objectName.propertyName) or bracket notation (objectName["propertyName"]). Bracket notation enables dynamic property access using variables, which is useful for reducing repetitive code when working with managed tables and lookups.

    Practical Example: Dynamic Field Setting via Table Lookup

    CPQ scripts can leverage managed table lookups to dynamically update fields based on configuration inputs. For example, a script can read a shipState field value and retrieve corresponding Boolean and quantity fields from a managed table, setting them accordingly. This approach minimizes duplicated conditional logic by using a single lookup and loop to set multiple fields.

    If shipState is empty or null, the script sets default values for all Boolean and quantity fields from the table.

    Support and Further Resources

    If functionality beyond this reference is needed, customers are encouraged to open a support case via the ServiceNow Support portal. Additional related resources include guides on debugging scripts with comments and console, handling first and subsequent configurations, and sample scripts.

    View the operators, objects, and keywords that CPQ supports, together with information about type conversion, type checking, alternative scripts for unsupported operations, and accessing object properties.

    CPQ uses a JavaScript-like language to dynamically change the value of fields and BOM data via rules and enrichments. JavaScript is a complex language built over almost thirty years, and while we are unable to replicate every piece of functionality that a developer would normally expect while coding, CPQ scripting remains a powerful tool to assist in the dynamic configuration of products.

    The capabilities of CPQ scripting are always expanding. Check back to see the most up-to-date features.

    Supported operators

    Arithmetic operators:

    +
    Addition
    -
    Subtraction
    *
    Multiplication
    /
    Division
    %
    Modulus
    ++
    Increment
    --
    Decrement

    String operators:

    +
    Concatenation
    +=
    Addition assignment

    Assignment operators:

    =
    Assignment
    +=
    Addition assignment
    -=
    Subtraction assignment

    Comparison operators:

    ==
    Equal to
    ===
    Equal value and equal type
    !=
    Not equal to
    !==
    Not equal value nor equal type
    >
    Greater than
    <
    Less than
    >=
    Greater than or equal to
    <=
    Less than or equal to

    Logical operators:

    &&
    And
    ||
    Or

    Supported objects

    Each object supported can be declared with the following:

    [ ]
    Array
    " "
    String
    ( )
    Number
    true | false
    Boolean
    { }, new Map( )
    Map
    new Date( )
    Date

    undefined, NaN, and null are unsupported.

    Note:
    Date objects cannot be returned, but they can be referenced and manipulated with the Date APIs in the Help menu.

    Supported keywords

    • var
    • let
    • const
    • new
    • if
    • else if
    • else
    • for
    • for/of
    • return

    We do not support while or unconditional for loops with break, because of the risk of infinite loops halting performance.

    We do not support functions, as the script itself should be small enough to be considered one function. If your script is long with many conditions and variables, consider creating a managed table and using a table query. For more information about using managed tables and table queries, see Matrix Loader: CSV table upload and Minimizing table queries.

    Alternative scripts for unsupported operations

    Assignment multiplication and division (/= or *=): number = number * otherNumber;, number = number / otherNumber;

    Exponentiation (x**y): Math.pow(x, y);

    Type conversion

    Convert arrays to strings: Array.toString()

    Convert numbers to strings: [number] + ""

    Convert numeric strings to numbers: [string] - 0

    Note:
    Strings cannot be treated as arrays, but .length does work for strings.

    Type checking

    The following returns a Boolean value indicating whether an input is a number: LGK.isNumber(123)

    Accessing object properties

    You can access the properties of map objects such as cfgRequest in two ways.

    objectName.propertyName
    //or
    objectName["propertyName"]

    This is helpful in order to replace large amounts of repetitive code with results from a Table Lookup, since the “propertyName” text could instead be replaced by a variable.

    For example, consider a blueprint with the following fields associated with it, and a managed table named shipstatebooleantest.

    • shipState
    • boolean1
    • boolean2
    • boolean3
    • quantity1
    • quantity2
    • quantity3
    Table 1. shipstatebooleantest
    id shipState trueBoolean quantityTest rowQuantity
    1 Arizona boolean1 quantity1 1
    2 Maine boolean2 quantity2 2
    3 California boolean3 quantity3 3

    Instead of having an identical if statement check what shipState is and setting the Boolean values and quantities accordingly, you could instead replace it with only one if statement that sets the values based on the results of a table lookup.

    In the following On Configure/Reconfigure script, if the shipState field has a value, the fields that are returned by the lookup function are set. If the shipState field is blank, then all Boolean and quantity fields are set.

    if (cfgRequest.shipState.value != "" && cfgRequest.shipState.value != null){
    	var fieldMapping = lookup("Select trueBoolean,quantityTest,rowQuantity from shipstatebooleantest where shipState = :value", { "value": cfgRequest.shipState.value });
    	console.log(fieldMapping);
    	if (fieldMapping != []){
    		cfgRequest[fieldMapping[0].trueBoolean].set("value",true);
    		cfgRequest[fieldMapping[0].quantityTest].set("value",fieldMapping[0].rowQuantity);
    	}
    }
    else{
    	var fieldMapping = lookup("Select trueBoolean,quantityTest,rowQuantity from shipstatebooleantest");
      console.log(fieldMapping);
      for (var row of fieldMapping) {
     		cfgRequest[row.trueBoolean].set("value",true);
     		cfgRequest[row.quantityTest].set("value",row.rowQuantity);ea
      }
    } 
    If your instance of CPQ needs functionality not described here, create a support case by using the ServiceNow Support portal. For step-by-step instructions, see Create a case on Now Support for CPQ (Logik.ai) Customers.