--- title: ConsolidationService - Scoped, Gobal description: The ConsolidationServiceSNC 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 within a JSON can be deduplicated during consolidation. 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 deduplicates 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/api-reference/server-api-reference/ConsolidationServiceAPI.html release: brazil product: Server API Reference classification: server-api-reference topic_type: concept last_updated: "2026-09-10" reading_time_minutes: 17 breadcrumb: [Server API reference, API reference, API implementation and reference] --- # ConsolidationService- Scoped, Gobal The ConsolidationServiceSNC 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 ConsolidationServiceSNC API when you need precise control over how records are combined, such as deciding which items are duplicates, how attributes like quantities or dates are calculated, and how nested child records are handled. 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 deeply nested child structures. - Reusing the same consolidation logic consistently across flows and integrations. The ConsolidationServiceSNC is part of the Lead to Cash \(L2C\) Core primitives engine and is accessed via the LeadToCashCore application. ## ConsolidationServiceSNC API extension and workflow The ConsolidationServiceSNC API's base system is disabled by default to ensure that unwanted consolidation isn't applied unknowingly. To enable consolidation or deduplication actions, you must create custom logic and optionally override methods provided with the ConsolidationServiceSNC script include. To extend and use the ConsolidationServiceSNC 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 \(or enable\) any number of these additional methods: **Note:** If you don’t override any methods, `consolidate()` returns the target JSON unchanged with no merging or deduplication performed. |Method|Action| |------|------| |canConsolidateEntity\(contextType\)|Choose which child arrays to deduplicate 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. 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' }); ``` 5. Invoke your consolidation by calling LeadToCashService.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/brazil/markdown/api-reference/server-api-reference/api-server.md) ## ConsolidationService - canConsolidateEntity\(String contextType\) Overridable method for specifying which child entity types within a JSON can be deduplicated during consolidation. 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 \(that is, deduplication\) is possible on the selected entity type.Valid values: - true: Groups entities of this type by hash and deduplicates 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 consolidateJSONs\(\). - 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 |
|---|---|---|
| additionalParams | Object | Optional. Extra configuration parameters passed through to the consolidation methods. Stored on the instance as this.additionalParams and accessible in all overridable methods. Can contain any custom key-value pairs needed by the implementing class. |
| sourceJSON | Object | Output of Create/Effect primitive. Single JSON object or a JSON object containing an items array with multiple entity JSONs. Can be null or empty if only target consolidation is needed. If sourceJSON doesn't contain an items array, it's treated as a single entity and wrapped in an array. ``` "sourceJSON": { "items": [Array] } ``` |
| 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": [Array] ``` |
| 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 covered product entity JSONs associated with the line item. Follows the same structure as **sourceJSON.items.coveredProducts**.``` "coveredProducts": [Array] ``` | |
| sourceJSON.items.lineItems.sys\_id | Sys\_id of the entity JSONs line item. | |
| sourceJSON.items.lineItems.table | 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}, "entitlement_characteristic": {Object}, "sys_id": "String", "table": "String, "line_item": {Object} } } ``` |
| 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 covered product entity JSONs associated with the line item. Follows the same structure as **sourceJSON.items.coveredProducts**.``` "coveredProducts": [Array] ``` | |
| targetJSON.lineItems.sys\_id | Sys\_id of the entity JSONs line item. | |
| targetJSON.lineItems.table | 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` |
| Type | Description |
|---|---|
| Object | Consolidated JSON result. The merged and deduplicated 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. |