ConsolidationService - Scoped, Gobal

concept brazil Updated Sep 10, 2026 17 min read ConsolidationServiceAPI.md
Raw file servicenow.com

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:

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

    JavaScript
    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

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

The following example shows how to override canConsolidateEntity\(\) to enable consolidation for line items and covered products.
JavaScript
var MyConsolidationService = Class.create();
MyConsolidationService.prototype = Object.extendsObject(sn_l2c_core.ConsolidationService, {    enableConsolidation: function() {        return true;    },
    canConsolidateEntity: function(contextType) {        return contextType == "lineItems" || contextType == "coveredProducts";    },
    type: 'MyConsolidationService'});
var service = new MyConsolidationService();
gs.info("Can consolidate lineItems = " + service.canConsolidateEntity("lineItems"));
gs.info("Can consolidate characteristics = " + service.canConsolidateEntity("characteristics"));

Output:

Text
Can consolidate lineItems = trueCan consolidate characteristics = false

ConsolidationService - canConsolidateJSONs(Object json1, Object json2)

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.

Name Type Description
json1 Object First entity JSON to compare. Contains sys_id, table, attributes, and child arrays.
json2 Object Second entity JSON to compare. Contains sys_id, table, attributes, and child arrays.

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

This example shows how to override canConsolidateJSONs\(\) to allow consolidation of line items with the same product offering.
JavaScript
var MyConsolidationService = Class.create();
MyConsolidationService.prototype = Object.extendsObject(sn_l2c_core.ConsolidationService, {

    enableConsolidation: function() {
        return true;
    },

    canConsolidateJSONs: function(json1, json2) {
        if (json1.table == "sn_quote_mgmt_core_quote_line_item") {
            var po1 = json1.attributes.product_offering ? json1.attributes.product_offering.value : "";
            var po2 = json2.attributes.product_offering ? json2.attributes.product_offering.value : "";
            return po1 == po2 && po1 != "";
        }
        return false;
    },

    type: 'MyConsolidationService'
});

ConsolidationService - canMergeEntity(String contextType)

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.

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

The following example shows how to override canMergeEntity\(\) to enable merging for line items and covered products.
JavaScript
var MyConsolidationService = Class.create();
MyConsolidationService.prototype = Object.extendsObject(sn_l2c_core.ConsolidationService, {

    enableConsolidation: function() {
        return true;
    },

    canMergeEntity: function(contextType) {
        return contextType == "lineItems" || contextType == "coveredProducts";
    },

    type: 'MyConsolidationService'
});

var service = new MyConsolidationService();
gs.info("Can merge lineItems = " + service.canMergeEntity("lineItems"));
gs.info("Can merge characteristics = " + service.canMergeEntity("characteristics"));

Output:

Text
Can merge lineItems = trueCan merge characteristics = false

ConsolidationService - consolidate(Object sourceJSON, Object targetJSON, Object additionalParams)

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.

The consolidate() method acts as the main entry point for consolidating JSONs. This method handles both single JSON and multiple JSONs, via the items array, as source input.

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.

JavaScript
"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" } ]

Text
</td></tr><tr><td>
sourceJSON.items.attributes
</td><td>
Object
</td><td>
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" } ]

Text
</td></tr><tr><td>
sourceJSON.items.characteristics.attributes
</td><td>
Object
</td><td>
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" }

Text
</td></tr><tr><td>
sourceJSON.items.characteristics.attributes.value
</td><td>
Object
</td><td>
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]

Text
</td></tr><tr><td>
sourceJSON.items.lineItems
</td><td>
Array of Objects
</td><td>
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} }

Text
</td></tr><tr><td>
sourceJSON.items.lineItems.characteristic
</td><td>
Object
</td><td>
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]

Text
</td></tr><tr><td>
sourceJSON.items.lineItems.sys\_id
</td><td>
 
</td><td>
Sys\_id of the entity JSONs line item.
</td></tr><tr><td>
sourceJSON.items.lineItems.table
</td><td>
 
</td><td>
Table location of the entity JSONs line item.
</td></tr><tr><td>
sourceJSON.items.sys\_id
</td><td>
String
</td><td>
Sys\_id of the source entity record.
</td></tr><tr><td>
sourceJSON.items.table
</td><td>
String
</td><td>
Table name of the source entity. Example: `sn_pss_core_service_contract_line`.
</td></tr><tr><td>
targetJSON
</td><td>
Object
</td><td>
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"} }

Text
Example: `{ "product_offering": { "value": "xr48..." }, "quantity": { "value": "5" } }`
</td></tr><tr><td>
targetJSON.lineItems
</td><td>
Array of Objects
</td><td>
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} }

Text
</td></tr><tr><td>
targetJSON.lineItems.characteristics
</td><td>
Object
</td><td>
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]

Text
</td></tr><tr><td>
targetJSON.lineItems.sys\_id
</td><td>
 
</td><td>
Sys\_id of the entity JSONs line item.
</td></tr><tr><td>
targetJSON.lineItems.table
</td><td>
 
</td><td>
Table location of the entity JSONs line item.
</td></tr><tr><td>
targetJSON.sys\_id
</td><td>
String
</td><td>
Sys\_id of the target entity record.
</td></tr><tr><td>
targetJSON.table
</td><td>
String
</td><td>
Table name of the target entity. Example: `sn_pss_core_service_contract`
</td></tr></tbody></table><table id="table_zch_wng_53c" class="returns"><thead><tr><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
Object
</td><td>
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.
</td></tr></tbody></table>The following example shows how to invoke the consolidate method via LeadToCashService. It consolidates a source entity JSON containing line items into a target entity JSON. Line items with the same product offering are deduplicated.
**Note:** MyConsolidationService is a custom script include that needs to be created by extending ConsolidationService. The logic for the overridable methods \(enableConsolidation, getHashConfig, canConsolidateEntity, canMergeEntity, canConsolidateJSONs, overrideAttributeValues\) needs to be added within MyConsolidationService. MyLeadToCashService extends LeadToCashService and returns MyConsolidationService from getConsolidationService\(\).

var sourceToTargetConfigID = "sn_cont_ent_wf_contract_to_quote";

var util = new sn_l2c_core.LeadToCashService(sourceToTargetConfigID);

var sourceJSON = { "items": [{ "sys_id": "a1b2c3d4e5f6", "table": "sn_pss_core_service_contract_line", "attributes": { "product_offering": { "value": "po_001" }, "quantity": { "value": "5" }, "start_date": { "value": "2026-01-01" }, "end_date": { "value": "2026-12-31" } }, "characteristics": [{ "sys_id": "ch_001", "table": "sn_pss_core_entitlement_characteristic", "attributes": { "characteristic": { "value": "speed" }, "value": { "value": "100mbps" } } }], "coveredProducts": [] }] };

var targetJSON = { "sys_id": "t1a2b3c4d5e6", "table": "sn_quote_mgmt_core_quote", "attributes": { "account": { "value": "acct_001" } }, "lineItems": [{ "sys_id": "li_001", "table": "sn_quote_mgmt_core_quote_line_item", "attributes": { "product_offering": { "value": "po_001" }, "quantity": { "value": "3" }, "start_date": { "value": "2026-03-01" }, "end_date": { "value": "2026-11-30" } }, "characteristics": [{ "sys_id": "ch_002", "table": "sn_pss_core_entitlement_characteristic", "attributes": { "characteristic": { "value": "speed" }, "value": { "value": "100mbps" } } }], "coveredProducts": [] }] };

var additionalParams = {}; var output = util.consolidate(sourceJSON, targetJSON, additionalParams); gs.info("Consolidated output = " + JSON.stringify(output));

Text
Output:

{ "sys_id": "t1a2b3c4d5e6", "table": "sn_quote_mgmt_core_quote", "attributes": { "account": { "value": "acct_001" } }, "lineItems": [ { "sys_id": "li_001", "table": "sn_quote_mgmt_core_quote_line_item", "attributes": { "product_offering": { "value": "po_001" }, "quantity": { "value": "8" }, "start_date": { "value": "2026-01-01" }, "end_date": { "value": "2026-12-31" } }, "characteristics": [ { "sys_id": "ch_002", "table": "sn_pss_core_entitlement_characteristic", "attributes": { "characteristic": { "value": "speed" }, "value": { "value": "100mbps" } } } ], "coveredProducts": [] } ] }

SQL
The following example shows how to invoke the consolidate method with null sourceJSON. In this case, only the child entities within the targetJSON are consolidated \(deduplicated\). This is useful when the target already contains duplicate line items that need to be merged.

var sourceToTargetConfigID = "sn_cont_ent_wf_contract_to_quote";

var util = new sn_l2c_core.LeadToCashService(sourceToTargetConfigID);

var targetJSON = { "sys_id": "t1a2b3c4d5e6", "table": "sn_quote_mgmt_core_quote", "attributes": { "account": { "value": "acct_001" } }, "lineItems": [{ "sys_id": "li_001", "table": "sn_quote_mgmt_core_quote_line_item", "attributes": { "product_offering": { "value": "po_001" }, "quantity": { "value": "5" } }, "characteristics": [], "coveredProducts": [] }, { "sys_id": "li_002", "table": "sn_quote_mgmt_core_quote_line_item", "attributes": { "product_offering": { "value": "po_001" }, "quantity": { "value": "3" } }, "characteristics": [], "coveredProducts": [] } ] };

var output = util.consolidate(null, targetJSON, {});

gs.info("Consolidated output = " + JSON.stringify(output));

Text
Output:

{ "sys_id": "t1a2b3c4d5e6", "table": "sn_quote_mgmt_core_quote", "attributes": { "account": { "value": "acct_001" } }, "lineItems": [ { "sys_id": "li_001", "table": "sn_quote_mgmt_core_quote_line_item", "attributes": { "product_offering": { "value": "po_001" }, "quantity": { "value": "8" } }, "characteristics": [], "coveredProducts": [] } ] }

Text
## ConsolidationService - enableConsolidation\(\)
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.
|Name|Type|Description||----|----|-----------||None| | |
<table id="table_lsg_jzg_53c" class="returns"><thead><tr><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
Boolean
</td><td>
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
</td></tr></tbody></table>The following example shows how to override enableConsolidation\(\) in a custom ConsolidationService.
**Note:** MyConsolidationService is a custom script include that must be created by extending ConsolidationService.

var MyConsolidationService = Class.create();

MyConsolidationService.prototype = Object.extendsObject(sn_l2c_core.ConsolidationService, { enableConsolidation: function() { return true; },

type: 'MyConsolidationService'

});

var service = new MyConsolidationService();

var isEnabled = service.enableConsolidation();

gs.info("Consolidation enabled = " + isEnabled);

Text
Output:

Consolidation enabled = true

Text
## ConsolidationService - getHashConfig\(\)
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.
|Name|Type|Description||----|----|-----------||None| | |
<table id="table_rcw_zdh_53c" class="returns"><thead><tr><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
Object
</td><td>
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.
</td></tr></tbody></table>The following example shows how to override getHashConfig\(\) to define hash attributes for contract lines and entitlement characteristics.

var MyConsolidationService = Class.create();

MyConsolidationService.prototype = Object.extendsObject(sn_l2c_core.ConsolidationService, {

enableConsolidation: function() {

    return true;

},


getHashConfig: function() {

    return {

        "sn_quote_mgmt_core_quote_line_item": {

            "attributes": ["product_offering"],

            "childContextTypes": ["sn_pss_core_entitlement_characteristic"]

        },

        "sn_pss_core_entitlement_characteristic": {

            "attributes": ["characteristic", "option", "value"]

        },

        "sn_pss_core_covered_product": {

            "attributes": ["sold_product"]

        }

    };

},


type: 'MyConsolidationService'

});

var service = new MyConsolidationService();

var config = service.getHashConfig();

gs.info("Hash config = " + JSON.stringify(config));

Text
Output:

Hash config = { "sn_quote_mgmt_core_quote_line_item": { "attributes": ["product_offering"], "childContextTypes": ["sn_pss_core_entitlement_characteristic"] }, "sn_pss_core_entitlement_characteristic": { "attributes": ["characteristic", "option", "value"] }, "sn_pss_core_covered_product": { "attributes": ["sold_product"] } }

Text
## ConsolidationService - getPrimary\(Object json1, Object json2\)
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.
|Name|Type|Description||----|----|-----------||json1|Object|First entity JSON to consolidate. Contains sys\_id, table, attributes, and child arrays.||json2|Object|Second entity JSON to consolidate. Contains sys\_id, table, attributes, and child arrays.|
|Type|Description||----|-----------||Object|The selected primary JSON. This JSON's attributes become the default values on the consolidated result. Must be either json1 or json2. The base implementation returns json1 if not overridden.|
The following example shows how to override getPrimary\(\) to select the entity with the earlier start date as primary.

var MyConsolidationService = Class.create();

MyConsolidationService.prototype = Object.extendsObject(sn_l2c_core.ConsolidationService, {

enableConsolidation: function() {

    return true;

},


getPrimary: function(json1, json2) {

    var date1 = json1.attributes.start_date ? json1.attributes.start_date.value : "";

    var date2 = json2.attributes.start_date ? json2.attributes.start_date.value : "";

    return date1 <= date2 ? json1 : json2;

},


type: 'MyConsolidationService'

});

Text
## ConsolidationService - overrideAttributeValues\(Object json1, Object json2, Object consolidatedJSON\)
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.
Common use cases include quantity summation, date range calculation \(earliest start / latest end\), term recalculation, and consolidated\_from tracking.
|Name|Type|Description||----|----|-----------||json1|Object|First entity JSON that was consolidated. This is the primary JSON \(as determined by getPrimary\(\)\). Contains original attributes before consolidation.||json2|Object|Second entity JSON that was consolidated. This is the secondary JSON. Contains original attributes before consolidation.||consolidatedJSON|Object|The result JSON after merging. Modify this object's attributes directly to apply custom logic. Initially contains a deep copy of the primary JSON's attributes with merged child arrays.|
|Type|Description||----|-----------||void|This method doesn't return a value. Modify the **consolidatedJSON** object directly.|
The following example shows how to override overrideAttributeValues\(\) to sum quantities and calculate date ranges when consolidating line items.

var MyConsolidationService = Class.create();

MyConsolidationService.prototype = Object.extendsObject(sn_l2c_core.ConsolidationService, {

enableConsolidation: function() {

    return true;

},


overrideAttributeValues: function(json1, json2, consolidatedJSON) {

    // Sum quantities

    var qty1 = parseInt(json1.attributes.quantity ? json1.attributes.quantity.value : "0");

    var qty2 = parseInt(json2.attributes.quantity ? json2.attributes.quantity.value : "0");

    consolidatedJSON.attributes.quantity = {
        "value": String(qty1 + qty2)
    };


    // Earliest start date

    var start1 = json1.attributes.start_date ? json1.attributes.start_date.value : "";

    var start2 = json2.attributes.start_date ? json2.attributes.start_date.value : "";

    consolidatedJSON.attributes.start_date = {
        "value": start1 <= start2 ? start1 : start2
    };


    // Latest end date

    var end1 = json1.attributes.end_date ? json1.attributes.end_date.value : "";

    var end2 = json2.attributes.end_date ? json2.attributes.end_date.value : "";

    consolidatedJSON.attributes.end_date = {
        "value": end1 >= end2 ? end1 : end2
    };


    // Track which entities were consolidated

    var consolidatedFrom = [];

    if (json1.sys_id) consolidatedFrom.push(json1.sys_id);

    if (json2.sys_id) consolidatedFrom.push(json2.sys_id);

    consolidatedJSON.attributes.consolidated_from = {
        "value": consolidatedFrom.join(",")
    };

},


type: 'MyConsolidationService'

});

Text
## ConsolidationService - postHierarchyConsolidation\(Object consolidatedJSON\)
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.
The system calls this method on the final consolidated result in the consolidate\(\) method, and also on each result entity within processHashGroup\(\).
|Name|Type|Description||----|----|-----------||consolidatedJSON|Object|Fully processed consolidated JSON object after all merging and deduplication is complete. Modify this object directly to apply final transformations.|
|Type|Description||----|-----------||void|This method doesn't return a value. Modify the **consolidatedJSON** object directly.|
The following example shows how to override postHierarchyConsolidation\(\) to set a flag on the consolidated entity.

var MyConsolidationService = Class.create();

MyConsolidationService.prototype = Object.extendsObject(sn_l2c_core.ConsolidationService, {

enableConsolidation: function() {

    return true;

},


postHierarchyConsolidation: function(consolidatedJSON) {

    if (consolidatedJSON && consolidatedJSON.attributes) {

        consolidatedJSON.attributes.is_consolidated = {
            "value": "true"
        };

    }

},


type: 'MyConsolidationService'

});

Text
## ConsolidationService - preProcess\(Object sourceJSON, Object targetJSON, Object additionalParams\)
Overridable method called before merge and consolidation for performing custom pre-processing tasks such as bulk map creation or caching lookup data..
Store computed results on the `this` object \(for example, `this.targetHeaderId = "sample_sys_id"`\). This method doesn't return any value.
|Name|Type|Description||----|----|-----------||sourceTarget|Object|Output of Create/Effect primitive. Source JSON\(s\) to consolidate. Can be null or empty.||targetJSON|Object|Required. Target entity JSON for consolidation.||additionalParams|Object|Optional. Additional data passed from the caller.|
|Type|Description||----|-----------||void|This method doesn't return any value. Store computed results on the `this` object for use in subsequent consolidation steps.|
The following example shows how to override preProcess\(\) to cache a target header ID for use during consolidation.

var MyConsolidationService = Class.create(); MyConsolidationService.prototype = Object.extendsObject(sn_l2c_core.ConsolidationService, {

enableConsolidation: function() {
    return true;
},

preProcess: function(sourceJSON, targetJSON, additionalParams) {
    this.targetHeaderId = targetJSON.sys_id;
    this.sourceCount = sourceJSON && sourceJSON.items ? sourceJSON.items.length : 0;
},

type: 'MyConsolidationService'

});

Text

Search documentation
Search document titles and file paths on the brazil branch