---
sourceDocument: Australia Sales Customer Relationship Management
sourceDocumentLink: https://www.servicenow.com/docs/r/australia/order-management

 Release :

    - australia

ft:locale :

    - en-US

ft:publication_title :

    - Australia Sales Customer Relationship Management

ft:clusterId :

    - omgmt

bundleId :

    - omgmt

workflow :

    - Customer and Industry


---

# General guidelines for scripting

# General guidelines for scripting {#ariaid-title1}

Release version: Australia  
Updated March 12, 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read
Summarize  
![AI sparkle icon](https://servicenow.com/docs/portal-asset/ai-sparkle-icon) 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 General guidelines for scripting

This guide provides essential best practices for writing efficient, readable, and maintainable scripts in ServiceNow CPQ using a JavaScript-like language.
Following these guidelines helps optimize script performance, improve code clarity, and reduce errors in your CPQ customizations.
Show full answer Show less  

## Key Guidelines

* **Place declarations at the top:** Declare variables and functions at the beginning of your script to enhance readability and avoid hoisting issues.
* **Comment thoughtfully:** Use comments to clarify complex logic or assumptions but avoid redundant comments that merely restate the code.
* **Indent brackets properly:** Maintain consistent indentation, especially with nested blocks, to improve code structure and readability.
* **Use descriptive and consistent variable names:** Choose meaningful names that clearly convey purpose, and adopt a consistent naming convention---camelCase is preferred in ServiceNow CPQ.
* **Avoid the `new` keyword:** Use literal notation for objects and primitives to reduce resource usage and prevent memory leaks (e.g., `{}` instead of `new Map()`, `[]` instead of `new Array()`).
* **Avoid loose equality (`==`):** Use strict equality (`===`) to prevent unexpected type coercion and ensure accurate comparisons.
* **Prefer `const` over `let`, and `let` over `var`:** Use `const` for variables that do not change and `let` for those that do, avoiding `var` except for legacy compatibility.
* **Minimize table lookups:** Reduce performance impacts by limiting database queries; retrieve data once and store in variables rather than querying repeatedly.

## Practical Impact for ServiceNow Customers

Adhering to these scripting guidelines enables you to create CPQ scripts that are easier to understand, maintain, and troubleshoot. Efficient variable declarations, clear naming, and minimized table lookups contribute to better performance and reduce the likelihood of runtime errors or unexpected behavior in your CPQ implementations.

By following this guidance, your development teams can produce higher quality scripts that align with ServiceNow best practices, facilitating smoother upgrades and ongoing enhancements.  
Write efficient scripts using a JavaScript-like language. Follow these general guidelines for naming, variables, and table access.

This guide will walk you through the general guidelines for writing efficient and reliable scripts in ServiceNow CPQ using a JavaScript-like language. Following these guidelines will help you create maintainable, readable, and well-performing code.

## Quick summary {#cpq-scripting-best-practicws__section_oys_xwl_rgc}

* Place declarations at the top
* Comment thoughtfully
* Indent brackets
* Use descriptive variable names
* Name variables consistently
* Avoid "new"
* Avoid loose equality ("==")
* Use "const" before "let" and "let" over "var"
* Minimize table lookups
{#cpq-scripting-best-practicws__ul_uky_d1m_rgc}

## Place declarations at the top {#cpq-scripting-best-practicws__section_k5x_ywl_rgc}

Placing variable and function declarations at the top of your script improves readability and prevents unexpected variable hoisting issues.

    1 // Declare and initiate at the beginning
    2 let firstName = "";
    3 let lastName = "";
    4 let price = 0;
    5 let discount = 0;
    6 let fullPrice = 0,
    7 const myArray = [];
    8 const myMap= {};

## Comment thoughtfully {#cpq-scripting-best-practicws__section_i1h_3xl_rgc}

Use comments to explain complex logic, assumptions, or any non-obvious behavior in your code. Avoid redundant comments that merely repeat the code.

## Indent brackets {#cpq-scripting-best-practicws__section_uwp_cxl_rgc}

Properly indenting your code improves its visual structure and makes it easier to understand, especially when dealing with nested blocks.

    1 // Good
    2 if (condition) {
    3 // ...
    4 if (nestedCondition) {
    5 // ...
    6 }
    7 }
    8
    9 // Bad
    10 if (condition) {
    11 // ...
    12 if (nestedCondition) {
    13 // ...
    14 }
    15 }

## Use descriptive variable names {#cpq-scripting-best-practicws__section_ecf_hxl_rgc}

Choose names that are meaningful and describe the purpose of the variable or function. This makes your code self- documenting and easier for others to understand.

    1 //Good
    2 let quoteId = cfgRequest.partner.quote.id.value;
    3 let lineID = cfgRequest.partner.quote.lineId.value;
    4 let currencyISO = cfgRequest.partner.quote.currencyIsoCode.value;
    5 let priceBookID = cfgRequest.partner.quote.pricebookId.value;
    6
    7 if (quoteId != null) {
    8 cfgRequest.quoteIDTest.set("value", quoteId);
    9 }
    10
    11 if (lineID != null) {
    12 cfgRequest.lineIDTest.set("value", lineID);
    13 }
    14
    15 if (currencyISO != null) {
    16 cfgRequest.currencyISOCodeTest.set("value", currencyISO);
    17 }
    18
    19 if (priceBookID != null) {
    20 cfgRequest.pricebookIDTest.set("value", priceBookID);
    21 }
    22
    23 //Bad
    24 let x1= cfgRequest.partner.quote.id.value;
    25 let x2= cfgRequest.partner.quote.lineId.value;
    26 let x3= cfgRequest.partner.quote.currencyIsoCode.value;
    27 let x4= cfgRequest.partner.quote.pricebookId.value;
    28
    29 if (x1 != null) {
    30 cfgRequest.quoteIDTest.set("value", x1);
    31 }
    32
    33 if (x2 != null) {
    34 cfgRequest.lineIDTest.set("value", x2);
    35 }
    36
    37 if (x3 != null) {
    38 cfgRequest.currencyISOCodeTest.set("value", x3);
    39 }
    40
    41 if (x4 != null) {
    42 cfgRequest.pricebookIDTest.set("value", x4);
    43 }

## Name variables consistently {#cpq-scripting-best-practicws__section_vq4_bxl_rgc}

Consistent naming conventions enhance code readability and maintainability. Choose either camelCase or snake_case and stick to it. ServiceNow CPQ field variable names use camelCase, so most organizations stay with this convention for readability.

    1 // camelCase
    2 let firstName = "JohnDoe";
    3
    4 // snake_case
    5 let last_name = "Smith";

## Avoid the "new" keyword {#cpq-scripting-best-practicws__section_czq_zwl_rgc}

Using the `new` keyword can use more resources, lead to memory leaks, and cause unintended behaviors. Instead, use the literal notation for object creation if possible.

* Use `" "` instead of `new String( )`
* Use `( )` instead of `new Number( )`
* Use `false` instead of `new Boolean( )`
* Use `{ }` instead of `new Map( )`
* Use `[ ]` instead of `new Array( )`
{#cpq-scripting-best-practicws__ul_gyx_zyl_rgc}

## Avoid loose equality ("==") {#cpq-scripting-best-practicws__section_epf_1xl_rgc}

The loose equality operator can lead to unexpected type coercion. For accurate comparisons, use the strict equality operator (`===`).

    1 // Good
    2 if (count === 5) {
    3 // ...
    4 }
    5
    6 // Bad
    7 if (count == "5") {
    8 // ...
    9 }

## Use "const" before "let" and "let" over "var" {#cpq-scripting-best-practicws__section_ksz_dxl_rgc}

Choose variable declaration based on scope and mutability requirements. Use `const` for variables that won't be reassigned and `let` for variables that will change. `var` is also acceptable
but is a holdover from previous versions of JavaScript.

    1 // Using const for unchanging values
    2 const TAX_RATE = 0.15;
    3
    4 // Using let for mutable values
    5 let itemCount = 5;

## Minimize table lookups {#cpq-scripting-best-practicws__section_zfp_gxl_rgc}

Excessive table queries can impact performance. Minimize queries by fetching necessary data once and storing it in variables.

To learn about general guideliines for using the `lookup` function, see [Minimizing table queries](https://www.servicenow.com/docs/acroFcGGB9WgRppWd3Vr8w "Learn how to minimize queries to maximize performance.").
**Related concepts**   

* [Create scripts](https://www.servicenow.com/docs/lLLO7eBPztvD88bl_rY0AQ "Learn how to create advanced functions using the scripting interface.")  
**Related reference**   

* [ServiceNow CPQ scripting language reference](https://www.servicenow.com/docs/oe31WnKg~IDVUFHcczalIQ "View the operators, objects, and keywords that ServiceNow CPQ supports, together with information about type conversion, type checking, alternative scripts for unsupported operations, and accessing object properties.")

