--- title: ConsolidationService - Scoped, Global description: The ConsolidationService API is a script include with methods for merging and de-duplicating complex, hierarchical business data \(such as contracts, quotes, line items, and entitlements\) using custom logic.Overridable method for specifying which child entity types can be consolidated within a JSON. The base implementation returns false for all entity types if not overridden.Overridable method that adds conditions for determining whether two entity JSONs with the same hash can be consolidated. The base implementation returns false if not overridden.Overridable method for specifying which child entity types can be merged from source JSONs into the target JSON. The base implementation returns false for all entity types if not overridden.Merges source entity JSON\(s\) into a target entity JSON and consolidates child entities within the merged result based on hash-based grouping and pairwise consolidation logic.Overridable method that controls whether consolidation is enabled for this service instance. The base implementation returns false if not overridden. Implementing classes must override this method to return true to enable consolidation.Overridable method that returns the hash configuration for grouping entities before consolidation. The configuration specifies which attributes and child context types generate an MD5 hash for each entity. Entities with the same hash are grouped for pairwise consolidation. The base implementation returns an empty object when not overridden.Overridable method to determine the primary JSON when two JSONs are being consolidated. For non-overridden attributes, the primary JSON's attribute values are used on the consolidated result. The base implementation returns json1 if not overridden.Overridable method, called after two JSONs are consolidated, for updating attributes on the consolidated JSON. The base implementation is a no-op if not overridden.Overridable method that applies final modifications to the consolidated JSON after hierarchy consolidation is complete. The base implementation is a no-op if not overridden.Overridable method called before merge and consolidation for performing custom pre-processing tasks such as bulk map creation or caching lookup data. locale: en-US canonical_url: https://www.servicenow.com/docs/r/australia/api-reference/server-api-reference/ConsolidationServiceAPI.html release: australia product: Server API Reference classification: server-api-reference topic_type: concept last_updated: "2026-04-01" reading_time_minutes: 22 breadcrumb: [Server API reference, API reference, API implementation and reference] --- # ConsolidationService- Scoped, Global The ConsolidationService API is a script include with methods for merging and de-duplicating complex, hierarchical business data \(such as contracts, quotes, line items, and entitlements\) using custom logic. This API belongs to the sn\_l2c\_core namespace, and requires the admin role and the Lead to Cash Core \(com.snc.l2c\_core\) plugin to access it. Use the ConsolidationService API when you need precise control over how records are combined. This API provides complex functionality not available on the UI, such as: - Defining what makes two records the same across multiple attributes or nested child entities. - Conditionally merging records when certain criteria are met. - Applying custom calculations during consolidation, like summing quantities or calculating date ranges. - Recursively deduplicating \(consolidating\) deeply nested child structures. - Reusing the same consolidation logic consistently across flows and integrations. The ConsolidationService is part of the Lead to Cash Core primitives engine and is accessed via the Lead to Cash Core product. ## Before you begin Before implementing ConsolidationService, ensure you have: - The Lead to Cash Core plugin \(`com.snc.l2c_core`\) installed and the `admin` role. - Two custom script includes: a `ConsolidationService` subclass containing your consolidation logic, and a `LeadToCashService` subclass that returns it from `getConsolidationService()`. The subclass wires your consolidation logic into the pipeline so PrimitiveUtil can resolve it at runtime. See the 'Extension and workflow' section for more information. - Familiarity with PrimitiveUtil, which is the entry point for invoking L2C Core primitives, including consolidation. See [LeadtoCashCore - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/LeadToCashCoreAPI.md) for more information. **Note:** If no custom implementation is registered, PrimitiveUtil falls back to the base `sn_l2c_core.LeadToCashService` automatically which has consolidation disabled by default, meaning no merging or deduplication is performed. You never need to instantiate or reference this fallback directly in your code. ## ConsolidationService API extension and workflow The ConsolidationService API's base system is disabled by default to ensure that unwanted consolidation isn't applied unknowingly. To enable consolidation actions, you must create custom logic and optionally override methods provided with the ConsolidationService script include. To extend and use the ConsolidationService API: 1. Required. Create a custom script include that extends `sn_l2c_core.ConsolidationService`. 2. Required. Override enableConsolidation\(\) to return `true`. This flag enables the system to allow consolidation on your service. Example script: ``` var MyConsolidationService = Class.create(); MyConsolidationService.prototype = Object.extendsObject( sn_l2c_core.ConsolidationService, { enableConsolidation: function () { return true; // REQUIRED }, type: 'MyConsolidationService' }); ``` 3. Depending on the entities you want to control, optionally override any number of these additional methods: **Note:** If you don’t override any methods, `consolidate()` returns the target JSON unchanged with no merging or consolidation performed. |Method|Action| |------|------| |canConsolidateEntity\(contextType\)|Choose which child arrays to consolidate within a target.| |canMergeEntity\(contextType\)|Merge source children into a target.| |getHashConfig\(\)|Specify how entities are grouped \(hashing\).| |canConsolidateJSONs\(json1, json2\)|Decide if two JSONs should merge.| |overrideAttributeValues\(\)|Apply custom business logic after a merge and before the final consolidated JSON continues through the workflow.| |getPrimary\(json1, json2\)|Decides which of the two entities is treated as the primary record during consolidation, whose attribute values are retained by default in the merged result.| |preProcess\(\)|Pre-hook for computing data.| |postHierarchyConsolidation\(\)|Post-hook for final cleanup.| 4. Register your custom `ConsolidationService` against the extension point so that PrimitiveUtil can resolve it at runtime. 5. Return your custom `ConsolidationService` from `sn_l2c_core.LeadToCashService`. `LeadToCashService` is the entry point that wires your consolidation logic into the Lead‑to‑Cash pipeline so that it's actually used whenever consolidation is invoked. Example script: ``` var MyLeadToCashService = Class.create(); MyLeadToCashService.prototype = Object.extendsObject( sn_l2c_core.LeadToCashService, { getConsolidationService: function () { return new MyConsolidationService(); }, type: 'MyLeadToCashService' }); ``` 6. Invoke your consolidation by calling consolidate\(\) either directly from a server‑side script or indirectly via Lead‑to‑Cash Flow Designer primitives. **Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md) ## ConsolidationService - canConsolidateEntity\(String contextType\) Overridable method for specifying which child entity types can be consolidated within a JSON. The base implementation returns `false` for all entity types if not overridden. |Name|Type|Description| |----|----|-----------| |contextType|String|The key name of the array property on the entity JSON representing the child entity type. Examples: `"lineItems"`, `"characteristics"`, `"coveredProducts"`.|
| Type | Description |
|---|---|
| Boolean | Flag indicating whether consolidation is possible on the selected entity type.Valid values: - true: Groups entities of this type by hash and consolidates them. - false: Doesn't consolidate entities of this type. Default: false |
| Type | Description |
|---|---|
| Boolean | Flag that indicates whether the two JSONs can be consolidated into one.Valid values: - true: Both JSONs can be merged via consolidate\(\). - false: Both JSONs remain separate. Default: false |
| Type | Description |
|---|---|
| Boolean | Flag that indicate whether entities of this type can be merged from source to target.Valid values: - true: The system concatenates source arrays of this type into the target's corresponding array. - false: The system doesn't merge source arrays of this type into the target. Default: false |
| Name | Type | Description |
|---|---|---|
| sourceJSON | Object | Accepts the JSON output of the [LeadtoCashCore - Scoped](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/LeadToCashCoreAPI.md) createInstance\(\) or effect\(\) method. Can be a single entity JSON object, or a JSON object containing an items array of multiple entity JSONs.If you're not piping output from another primitive, you can also construct this JSON manually following the structure below." ``` "sourceJSON": { "items": [Array] } ``` If sourceJSON doesn't contain an items array, the method treats it as a single entity and wraps it in an array automatically. Pass null or omit this parameter if only target consolidation is needed. |
| sourceJSON.items | Array of Objects | Optional. Array of entity JSONs to merge into the target. Each item represents an entity with its attributes and child arrays. If this property exists, **items** is used directly as the list of source entities.``` "items": [ { "attributes": {Object}, "characteristics": [Array], "coveredProducts": [Array], "sys_id": "String", "table": "String" } ] ``` |
| sourceJSON.items.attributes | Object | Key-value pairs representing the entity attributes. Each attribute is an object with a value property.``` "attributes": { "end_date": {"value": "String"}, "product_offering": {"value": "String"}, "quantity": {"value": "String"}, "start_date": {"value": "String"} } ``` Example: `{ "product_offering": { "value": "xr48..." }, "quantity": { "value": "5" } }` |
| sourceJSON.items.attributes.end\_date | String | End date of the attribute.Format: GlideDate value \(for example, 2026-01-01\) |
| sourceJSON.items.attributes.product\_offering | String | Name of the product offering associated with the attribute. Located in the Product Offering \[sn\_prd\_pm\_product\_offering\] table. |
| sourceJSON.items.attributes.quantity | String | Number of product items purchased relative to the attribute. |
| sourceJSON.items.attributes.start\_date | String | Start date of the attribute.Format: GlideDate value \(for example, 2026-01-01\) |
| sourceJSON.items.characteristics | Array of Objects | Optional. Array of characteristic entity JSONs.``` "characteristics": [ { "attributes": {Object}, "sys_id": "String", "table": "String" } ] ``` |
| sourceJSON.items.characteristics.attributes | Object | Attributes associated with the item characteristic. Each child property is a key-value pair representing the attribute. The attribute is an object with a value property.``` "attributes": { "characteristic": {Object}, "value": {Object} } ``` |
| sourceJSON.items.characteristics.attributes.characteristic | Object | Key-value pair representing the characteristic associated with the attribute. **characteristic** is an object with a value property.``` "characteristic": { "value": "String" } ``` |
| sourceJSON.items.characteristics.attributes.value | Object | Key-value pair representing the attribute value associated with the parent characteristic. **value** is an object with a value property.``` "value": { "value": "String" } ``` |
| sourceJSON.items.characteristics.sys\_id | String | Sys\_id of the characteristic associated with the item. |
| sourceJSON.items.characteristics.table | String | Table location of the characteristic associated with the item. |
| sourceJSON.items.coveredProducts | Array of Objects | Optional. Array of covered product entity JSONs.``` coveredProducts: [ { "sys_id": {Object}, "table": "String", "attributes": {Object} } ] ``` |
| sourceJSON.items.coveredProducts.sys\_id | Object | Sys\_id of the covered product record.``` sys_id: { value: "String" } ``` |
| sourceJSON.items.coveredProducts.table | String | Table name containing the covered product record. For example, `sn_install_base_m2m_contract_sold_product`. |
| sourceJSON.items.coveredProducts.attributes | Object | Attributes of the covered product. Fields may vary based on the record.``` attributes: { sold_product: { value: "String" }, contract: { value: "String" }, service_contract_line: { value: "String" }, entitlement: { value: "String" }, install_base: { value: "String" }, covering_sold_product: { value: "String" }, date_added: { value: "String" }, date_removed: { value: "String" } } ``` |
| sourceJSON.items.coveredProducts.attributes.sold\_product | Object | Sold product record associated with this covered product.``` "sold_product": { "value": "String" } ``` |
| sourceJSON.items.coveredProducts.attributes.contract | Object | Parent contract record under which coverage is defined.``` "contract": { "value": "String" } ``` |
| sourceJSON.items.coveredProducts.attributes.service\_contract\_line | Object | Specific service contract line item linked to this covered product.``` "service_contract_line": { "value": "String" } ``` |
| sourceJSON.items.coveredProducts.attributes.entitlement | Object | Entitlement record governing the coverage terms.``` "entitlement": { "value": "String" } ``` |
| sourceJSON.items.coveredProducts.attributes.install\_base | Object | Install base record representing the deployed asset.``` "install_base": { "value": "String" } ``` |
| sourceJSON.items.coveredProducts.attributes.covering\_sold\_product | Object | Sold product providing coverage for this entry.``` "covering_sold_product": { "value": "String" } ``` |
| sourceJSON.items.coveredProducts.attributes.date\_added | Object | ISO 8601 date string indicating when the product was added to coverage.``` "date_added": { "value": "String" } ``` |
| sourceJSON.items.coveredProducts.attributes.date\_removed | Object | ISO 8601 date string indicating when the product was removed from coverage. Null or empty if currently active.``` "date_removed": { "value": "String" } ``` |
| sourceJSON.items.lineItems | Array of Objects | Optional. Array of child line item entity JSONs. Each child follows the same structure \(sys\_id, table, attributes, and nested children\).``` "lineItems": [ { "attributes": {Object}, "characteristics": [Array], "coveredProducts": [Array], "sys_id": "String", "table": "String" } ] ``` |
| sourceJSON.items.lineItems.attributes | Object | Key-value pairs representing the entity attributes. Each attribute is an object with a value property. Follows the same structure as **sourceJSON.items.attributes**.``` "attributes": { "characteristic": {Object}, "value": {Object} } ``` |
| sourceJSON.items.lineItems.characteristic | Object | Key-value pairs representing the characteristic of the line item. The characteristic is an object with a value property. Follows the same structure as **sourceJSON.items.characteristics**.``` "characteristics": [{ "attributes": {Object}, "sys_id": "String", "table": "String" }] ``` |
| sourceJSON.items.lineItems.coveredProducts | Array of Objects | Array of covered product entity JSONs associated with the line item. Follows the same structure as **sourceJSON.items.coveredProducts**.``` coveredProducts: [ { "sys_id": {Object}, "table": "String", "attributes": {Object} } ] ``` |
| sourceJSON.items.lineItems.sys\_id | String | Sys\_id of the entity JSONs line item. |
| sourceJSON.items.lineItems.table | String | Table location of the entity JSONs line item. |
| sourceJSON.items.sys\_id | String | Sys\_id of the source entity record. |
| sourceJSON.items.table | String | Table name of the source entity. Example: `sn_pss_core_service_contract_line`. |
| targetJSON | Object | Required. Target entity JSON to consolidate the source JSON into. Must not be null or empty. Follows the same object structure as the source entity \(**sourceJSON** parameter\).``` targetJSON={ "attributes": {Object}, "lineitems": {Object}, "sys_id": "String", "table": "String" } } ``` |
| targetJSON.attributes | Object | Key-value pairs representing the target entity attributes. Each attribute is an object with a value property. Follows the same object structure as the source attributes \(**sourceJSON.items.attributes** parameter\).``` "attributes": { "end_date": {"value": "String"}, "product_offering": {"value": "String"}, "quantity": {"value": "String"}, "start_date": {"value": "String"} } ``` Example: `{ "product_offering": { "value": "xr48..." }, "quantity": { "value": "5" } }` |
| targetJSON.lineItems | Array of Objects | Optional. Array of child line item entity JSONs on the target. Follows the same object structure as **sourceJSON.items.lineItems**.``` "lineItems": { "sys_id": "String", "table": "String", "attributes": {Object}, "characteristics": {Object} } ``` |
| targetJSON.lineItems.attributes | Object | Key-value pairs representing the entity attributes. Each attribute is an object with a value property. Follows the same structure as **sourceJSON.items.attributes**.``` "attributes": { "characteristic": {Object}, "value": {Object} } ``` |
| targetJSON.lineItems.characteristics | Object | Key-value pairs representing the characteristic of the line item. The characteristic is an object with a value property. Follows the same structure as **sourceJSON.items.characteristics**.``` "characteristic": { "value": "String" } ``` |
| targetJSON.lineItems.coveredProducts | Array of Objects | Array of covered product entity JSONs associated with the line item. Follows the same structure as **sourceJSON.items.coveredProducts**.``` "coveredProducts": [Array] ``` |
| targetJSON.lineItems.sys\_id | String | Sys\_id of the entity JSONs line item. |
| targetJSON.lineItems.table | String | Table location of the entity JSONs line item. |
| targetJSON.sys\_id | String | Sys\_id of the target entity record. |
| targetJSON.table | String | Table name of the target entity. Example: `sn_pss_core_service_contract` |
| additionalParams | Object | Optional. Extra configuration parameters passed through to the consolidation methods. Stored on the instance as `this.additionalParams` and is accessible in all overridable methods. Can contain any custom key-value pairs needed by the implementing class. |
| Type | Description |
|---|---|
| Object | Consolidated JSON result. The merged and consolidated entity JSON contains all attributes from the target and merged/consolidated child arrays.Returns targetJSON if consolidation is disabled or sourceJSON is invalid. Returns null if targetJSON is null or empty. |
| Type | Description |
|---|---|
| Boolean | Flag that indicates whether the service has successfully enabled consolidation.Valid values: - true: Service is enabled for consolidation. - false: Service isn't enabled for consolidation. Default: false |
| Type | Description |
|---|---|
| Object | A JSON object mapping table names to their hash configuration. Each table entry contains: 1. attributes \(Array of Strings\): Attribute field names whose values are included in the hash. 2. childContextTypes \(Array of Strings\): Optional. Child table names whose hash values are recursively included in the parent hash. Expected return format: `{ "table_name": { "attributes": ["field1", "field2"], "childContextTypes": ["child_table_name"] } }` When the hash configuration for a table is an empty object `{}`, all entities of that type are consolidated into a single entity. When the hash configuration for a table isn't found \(undefined or null\), an error is logged and entities are returned unchanged. The base implementation returns an empty object when not overridden. |