---
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


---

# Sample scripts

# Sample scripts {#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 Sample scripts

This collection of sample scripts provides practical examples for ServiceNow CPQ customers to handle common configuration and product rule scenarios.
These scripts demonstrate how to calculate CPU core allocations, format multi-line text fields, generate product rule entries, use loops for product replication, work with arrays and maps, and manipulate picklist values and string concatenations.
Show full answer Show less  

## Key Features

* **CPU Core Count Calculations:** Scripts to determine counts of 64, 32, 16, 8, and 1 vCPUs based on compute capacity and configuration flags, enabling dynamic allocation of processing power.
* **Multi-line Text Field Assembly:** Construct formatted strings showing CPU counts for display in configuration interfaces.
* **Product Rule Scripting:** Examples to query product information from external sources and populate product lists with appropriate quantities, notes, and BOM types, supporting both sales and manufacturing workflows.
* **Looping for Product Replication:** Use of nested loops to replicate product line items multiple times, facilitating complex provisioning scenarios.
* **Array and Map Usage:** Lookup products in bulk, create maps for quick BOM type retrieval, and validate item types programmatically.
* **Handling Multi-select Picklist Fields:** Extract and set multi-select values from Salesforce to twinned multi-select fields in ServiceNow CPQ during configuration or reconfiguration events.
* **String Concatenation and Contains Logic:** Concatenate multiple field values into a single string and imitate "contains" functionality to execute conditional code based on substring presence.

## Practical Benefits for ServiceNow Customers

* Quickly implement CPU resource allocation logic tailored to your product catalog and compute constraints.
* Enhance user experience by formatting configuration summaries clearly.
* Automate product list generation with dynamic quantities and notes, ensuring accurate BOM and provisioning instructions.
* Efficiently replicate product configurations for bulk or clustered deployments.
* Leverage bulk data lookups and mapping to streamline product validations and categorization.
* Integrate Salesforce multi-select data seamlessly into ServiceNow CPQ configurations.
* Use simple scripting patterns for common text operations and conditional checks without complex syntax.  
View a selection of commonly requested sample scripts.
This article shows some commonly requested sample scripts.

Sample number field determination:

    var count64 = 0;
    var count32 = 0;
    var perCoreProcessing = 40; //assuming 8 processors with 5 TFlops compute
    var cpu64Processing = 64*perCoreProcessing;
    var cpu32Processing = 32*perCoreProcessing;
    var cpu16Processing = 16*perCoreProcessing;
    var remainingCompute = cfg.estPeakOps;
    if(cfg.allowCPU64 == true) { //64 core allowed so divide by that
    	count64 = remainingCompute/cpu64Processing;
    	remainingCompute = remainingCompute%cpu64Processing;
    }
    if(cfg.allowCPU32 == true) {
    	count32 = remainingCompute/cpu32Processing;
    	remainingCompute = remainingCompute%cpu32Processing;
    }
    return count32;

Sample text field determination:

    var retStr = "";
    retStr = retStr + "64 vCPUs: " + Math.round(cfg.cpu64Count);
    retStr = retStr + "\\n32 vCPUs: " + Math.round(cfg.cpu32Count);
    retStr = retStr + "\\n16 vCPUs: " + Math.round(cfg.cpu16Count);
    retStr = retStr + "\\n8 vCPUs: " + Math.round(cfg.cpu8Count);
    retStr = retStr + "\\n1 vCPUs: " + Math.round(cfg.cpu1Count);
    return retStr;

Sample product rule script:

    //Base Product
    var baseProductP2ID = "BP_ID";
    var inputs = {"g2BaseProduct": cfg.g2BaseProduct};
    var resultSet = lookup("SELECT Product2Id, ProductName FROM Dummytable WHERE ProductCode = :g2BaseProduct", inputs);
    for (var row of resultSet) {
    	ProductList.id = row.get("Product2Id");
    	ProductList.quantity = cfg.orderQty;
    	ProductList.bomType = "SALES";
    	ProductList.uom = "EA";
    	ProductList.level = 1;
    	ProductList.notes = row.get("ProductName");
    	ProductList.parentProduct = "01t5f000000uJgoAAE"; //parent product identifier. In this case top product being configured from SFDC
    	baseProductP2ID = row.get("Product2Id");
    	ProductList.uniqueIdentifier = baseProductP2ID; //Parent
    	...SF ProductID; not req'd if this has no other children
    	ProductList.next();
    	break;
    }

Sample product rule script with `for` loop:

    //var timesReplicate = cfg.numberOfComputeClusters; //this doesn't work yet.. If it does, we will replicate that many times easier
    var timesReplicate = [1,1,1,1,1,1,1,1,1,1]; //dummy 10 times loop based on 10x boolean true, Double loop for 100
    for (var parentStep of timesReplicate) {
    	for (var step of timesReplicate) {
    		if(cfg.cpu16Count > 0) {
    			ProductList.id = "01t5f000000v50CAAQ";
    			ProductList.quantity=Math.round(cfg.cpu16Count);
    			ProductList.notes="Provisioning " + Math.round(cfg.cpu16Count) + " number of 16 core vCPUs";
    			if(cfg.sendDirectlyToProvisioning == true) {
    				ProductList.bomType = "Manufacturing";
    				ProductList.level = 2;
    			} else {
    				ProductList.bomType = "SALES";
    			}
    			ProductList.next();
    		}
    		if(cfg.cpu8Count > 0) {
    			ProductList.id = "01t5f000000v50DAAQ";
    			ProductList.quantity=Math.round(cfg.cpu8Count);
    			ProductList.notes="Provisioning " + Math.round(cfg.cpu8Count) + " number of 8 core vCPUs";
    			if(cfg.sendDirectlyToProvisioning == true) {
    				ProductList.bomType = "Manufacturing";
    				ProductList.level = 2;
    			} else {
    				ProductList.bomType = "SALES";
    			}
    			ProductList.next();
    		}
    		if(cfg.cpu32Count > 0) {
    			ProductList.id = "01t5f000000v50BAAQ";
    			ProductList.quantity=Math.round(cfg.cpu32Count);
    			ProductList.notes="Provisioning " + Math.round(cfg.cpu32Count) + " number of 32 core vCPUs";
    			if(cfg.sendDirectlyToProvisioning == true) {
    				ProductList.bomType = "Manufacturing";
    				ProductList.level = 2;
    			} else {
    				ProductList.bomType = "SALES";
    			}
    			ProductList.next();
    		}
    		if(cfg.cpu64Count > 0) {
    			ProductList.id = "01t5f000000v50JAAQ";
    			ProductList.quantity=Math.round(cfg.cpu64Count);
    			ProductList.notes="Provisioning " + Math.round(cfg.cpu64Count) + " number of 64 core vCPUs";
    			if(cfg.sendDirectlyToProvisioning == true) {
    				ProductList.bomType = "Manufacturing";
    				ProductList.level = 2;
    			} else {
    				ProductList.bomType = "SALES";
    			}
    			ProductList.next();
    		}
    		if(cfg.cpu1Count > 0) {
    			ProductList.id = "01t5f000000v50SAAQ";
    			ProductList.quantity=Math.round(cfg.cpu1Count);
    			ProductList.notes="Provisioning " + Math.round(cfg.cpu1Count) + " number of 1 core vCPUs";
    			if(cfg.sendDirectlyToProvisioning == true) {
    				ProductList.bomType = "Manufacturing";
    				ProductList.level = 2;
    			} else {
    				ProductList.bomType = "SALES";
    			}
    			ProductList.next();
    		}
    	}
    }
    console.log("Added line items 100 times");
    return ProductList;

Sample array and map functions:

    var productidArr = ["test123", "chtest123"];
    var inputs = {"productids": productidArr};
    var resultSet = lookup("SELECT uniqueidentifier, bomtype FROM bominformation WHERE productid IN (:productids)", inputs);

    var prodTypeMap = new Map();
    for (var row of resultSet) {
    	prodTypeMap.set(row.get("uniqueidentifier"), row.get("bomtype"));
    }
    var itemTypeManuf = productidArr.every((value) => {return prodTypeMap.get(value) != "Manufacturing";});
    if (isGood == false) {
    	return "Sales type item found";
    }
    var summary = "";
    productidArr.forEach((item, index) => {summary += index + " " + item + ". ";});
    return summary;

How to pull multi-select picklist values from SFDC to twinned multi-select picklist field in ServiceNow CPQ in the On Configure/Reconfigure enrichment:

    let x = (cfgRequest.yourTwinnedLogikField.value).split(";");
    cfgRequest.yourTwinnedLogikField.set("value", x);
    return cfgRequest;

How to concatenate field values into a string:

    stringVar = "";
    stringVar = stringVar.concat(cfg.varible1, cfg.variable2, cfg.variable3);
    return stringVar;// returns selected values of "variable1variable2variable3"

How to imitate a CONTAINS function:

    var yourVariable = "Field Value"; // Replace with your actual Field value
    if (yourVariable.includes("CU")) {
    	// Code you wish to execute when Field Value contains "CU"
    } else if (yourVariable.includes("AL")) {
    	// Code you wish to execute when Field Value contains "AL"
    } else {
    	// Code you wish to execute when Field Value doesn't contain "CU" or "AL"
    };

**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.")

