LeadtoCashCore - Scoped

  • Release version: Washingtondc
  • Updated February 1, 2024
  • 23 minutes to read
  • The LeadtoCashCore script include provides methods to orchestrate a lead-to-cash workflow in the Lead to Cash Core life cycle.

    The Lead to Cash Core (com.snd.l2c.core) plugin must be activated for LeadtoCashCore script includes to be available in an instance. This script include belongs to the sn_l2c_core namespace and requires the admin role.

    In a Lead to Cash workflow, you map a source entity to a target entity. An entity is defined as a collection of tables. Source-to-target mapping allows you to transform the structure or content of the source entity to fit the structure or content needed in the target entity. The functionality provided by this script include represents the entity mapping feature available in the Lead to Cash feature. See Sales and Order Management workflows for more information.

    To complete a workflow using the LeadtoCash script include, you pass return parameters from one method to the next. Typically, you call these methods in the following order:

    1. LeadtoCashCore - createInstance(String headerSysIDs, String lineSysIDs, Boolean isTarget, Object additionalParams) - Fetches the data of a given entity. For example, customer order-related information including line items and their related data.

      Use the context parameter to declare one or more header or line IDs in the script. For such multi-select use cases, the output JSON contains a key items array where each entry represents a single entity object.

    2. LeadtoCashCore - delta(Object sourceJSON, Object dirtyJSON, Object additionalParams) - Compares two JSON inputs and identifies any changes that occurred between them. For example, when something is added, deleted, or modified in an entity.
    3. LeadtoCashCore - effect(Object sourceJSON, Object targetJSON, Object additionalParams) - Transforms the source JSON target into a target object.
    4. LeadtoCashCore - commitInstance(Object targetJSON, Object additionalParams) - Commits the transformation made in the effect() script include to the database.
    Note:
    If necessary, delta() may be skipped in this workflow. However, calling these methods out of order results in an unsuccessful workflow (for example, when calling commitInstance() and then effect()).

    Prerequisites

    Each of these methods are bundled with an extension point, sn_l2c_core.LeadToCashServiceEP. PrimitiveUtil() is a utility which provides methods to get the extension point service and invokes the script includes according to their available parameters. You must first provide PrimitiveUtil() with the getPrimitivesEPService() method, which specifies the table to get source and target information from. For more information, see LeadtoCashCore - getPrimitivesEPService(String sourceToTargetConfigID, Object context). Once PrimitiveUtil() and getPrimitivesEPService() are provided in the script, you can then call any of the createInstance(), delta(), effect(), or commitInstance() script includes as needed for your use case.

    Example Lead to Cash Core workflow script

    Though each of the available Lead to Cash Core script includes are documented individually, you can reference the following example to see how you can use these methods together to produce a Lead to Cash work flow.

    var util = new sn_l2c_core.PrimitiveUtil(); 
     
    var context = {"isMultiSelect": false}; // Set the context.isMultiSelect parameter as true to enable multi-select use cases
    
    //Flow: Creation of Order from a sold product 
    var service = util.getPrimitivesEPService('sn_l2c_cust_flows_sp_to_order', context);  
      
    //CREATE INSTANCE to get the data of sold product with sys_id '06670ba3c3adbd501caee74bb0013166' 
    var SPInstance = service.createInstance(null, '06670ba3c3adbd501caee74bb0013166');  
    gs.info("SPInstance: "+JSON.stringify(SPInstance));  
      
    // DELTA  
    // construct the dirtyJSON as required  
    var deltaOutput = service.delta(SPInstance, dirtyJSON);/  
    gs.info("deltaOutput: "+JSON.stringify(deltaOutput));  
      
    // EFFECT  
    var effectOutput = service.effect(deltaOutput);  
    gs.info("effectOutput: " + JSON.stringify(effectOutput));  
      
    // COMMIT INSTANCE 
    var commitOutput = service.commitInstance(effectOutput);  
    gs.info("commitOutput: " + JSON.stringify(commitOutput));  
    In our example, a customer purchased a sold product but now requests a modification on the existing sold product. The required modifications are provided in the form of a dirtyJSON. To apply these modifications, we call the Lead to Cash Core methods in the following order:
    1. The first call gets the existing sold product information using the createInstance() method.
    2. We then compare this source JSON with the dirty JSON using the delta() method, which returns a delta JSON.
    3. The delta() JSON is then transformed into a JSON of type order using the effect() method.
    4. The order JSON is committed to the database using the commitInstance() method.

    LeadtoCashCore - commitInstance(Object targetJSON, Object additionalParams)

    Commits the JSON of a given Lead to Cash entity to the instance, returns a status message with updated information, and updates the Lead to Cash Core Entity table as a result.

    Note:
    The LeadtoCashCore script include requires you to first call the scripted extension point PrimitiveUtil() with the LeadtoCashCore - getPrimitivesEPService(String sourceToTargetConfigID, Object context) utility method to trigger the implementation before calling commitInstance() in your script. Per each flow, get the service only once and use the same service for all LeadtoCashCore methods.
    Table 1. Parameters
    Name Type Description
    targetJSON Object JSON object containing the ‘glide_action’ of a target entity to commit. You can pass the output of the effect() method here.
    Note:
    ‘glide_action’ identifies the change action that occurred between the source and target JSON of a Lead to Cash entity.
    additionalParams Object Optional. Additional parameters to use.

    Future use.

    Table 2. Returns
    Type Description
    JSON Object JSON object containing details about the target entity record.
    { 
      "error": "String",
      "headerID": "String",
      "rootLineIDs": [Array],
      "status": "String"
    }

    Data type: Object

    error Error message that describes the failure of the commitInstance method.

    Data type: String

    headerID Sys_id of the target entity record created or updated by the commitInstance method.

    Data type: String

    rootLineIDs Sys_ids of the target entity records inserted, updated, or deleted by the commitInstance method.

    Data type: Array of Strings

    status Status message with a value of 'success' or 'failure'.

    Data type: String

    The following example shows how to use each LeadtoCashCore method to retrieve, apply, and commit the details of a source-to-target entity.

    //Utility to invoke commitInstance API 
    var util = new sn_l2c_core.PrimitiveUtil();  
     
    //Invokes the PrimitiveUtil extension point, picks an implementation based on sourceToTargetConfigID of a Lead to Cash (L2C) flow. The Mapping Config ID  in “sn_l2c_core_entity_mapping” table. 
    var service = util.getPrimitivesEPService('sp_order_macd'); 
     
    //Invoke commitInstance API with the required params 
    var commitOutput = service.commitInstance(effectOutput); 
     
    //Print the returned JSON 
    gs.info("commitOutput: "+JSON.stringify(commitOutput));  
    //The returned JSON can be used for subsequent operations.

    Output:

    { 
      "status": "success", 
      "error": "", 
      "headerID": "cc9b3db665e73510f877d71ec56bf7ed", 
      "rootLineIDs": [ 
        "0c9b3db665e73510f877d71ec56bf7f1" 
      ] 
    }

    LeadtoCashCore - createInstance(String headerSysIDs, String lineSysIDs, Boolean isTarget, Object additionalParams)

    Returns the data of one or more given entities with a JSON object containing various details such as header, lines, child lines, characteristics, and their attributes.

    Use the output JSON of the createInstance() method in subsequent methods of the Lead to Cash Core workflow such as delta(), effect(), and commitInstance().

    Note:
    The LeadtoCashCore script include requires you to first call the script utility method PrimitiveUtil() with the LeadtoCashCore - getPrimitivesEPService(String sourceToTargetConfigID, Object context) utility method to trigger the implementation before calling createInstance() in your script. Per each flow, get the service only once and use the same service for all LeadtoCashCore methods.

    Set the getPrimitivesEPService() boolean parameter context.isMultiSelect to true to enable createInstance() to pass multiple, comma-separated headerIDs or lineIDs at a time. Otherwise, you can only pass one ID at a time. See LeadtoCashCore - getPrimitivesEPService(String sourceToTargetConfigID, Object context) for more details.

    Table 3. Parameters
    Name Type Description
    headerSysIDs String Header sys_id(s) of an entity to retrieve data from. Required if you don't provide the lineSysIDs parameter. Pass null if you aren't passing any header sys_ids.

    To designate one or more header sys_ids in your script, set context.isMultiSelect = true in the getPrimitivesEPService() utility method. For more details, see the Parameters table in LeadtoCashCore - getPrimitivesEPService(String sourceToTargetConfigID, Object context).

    Note:
    At least one headerSysID or lineSysIDs parameter is required.
    lineSysIDs String Line item sys_id(s) of an entity to retrieve entity data from. Required if you don't provide headerSysIDs and if the entity structure starts with line items such as sold product.

    To designate one or more line item sys_ids in your script, set context.isMultiSelect = true in the getPrimitivesEPService() utility method. For more details, see the Parameters table in LeadtoCashCore - getPrimitivesEPService(String sourceToTargetConfigID, Object context).

    Note:
    At least one headerSysID or lineSysIDs parameter is required. If passing multiple lineSysIDs, all records must belong to the same headerSysID.
    isTarget Boolean Optional. Flag that determines whether to fetch target entity data.
    Valid values:
    • true: Fetch data of the target entity.
    • false: Don't fetch data of the target entity.

    Default: false

    additionalParams Object Optional. Additional parameters to use.
    "additionalParams": { 
        "skipLines": Boolean 
    } 
    additionalParams.skipLines Boolean Optional. Flag that indicates whether to fetch line items for the specified entity.
    Valid values:
    • true: Skip returning line items information for the entity.
    • false: Return line items information for the entity.

    Default: false

    Table 4. Returns
    Type Description
    JSON Object A JSON containing details of the entity record.
    Note:
    This JSON is used in the sourceJSON request parameter of LeadtoCashCore - delta(Object sourceJSON, Object dirtyJSON, Object additionalParams).

    Data type: Object

    { 
    “items”:{  
      "table": "string",  
      "sys_id": {  
        "value": "string"  
      },  
      "attributes": {  
        "contact": {  
          "value": "string"  
        },  
        "account": {  
          "value": "string"  
        }  
      },  
      "lineItems": [  
        {  
          "table": "string",  
          "sys_id": {  
            "value": "string"  
          },  
          "attributes": {  
            "name": {  
              "value": "string"  
            },  
            "account": {  
              "value": "string"  
            }  
          },  
          "lineItems": [  
            {  
              "table": "string",  
              "sys_id": {  
                "value": "string"  
              },  
              "attributes": {},  
              "lineItems": [],  
              "characteristics": []  
            }  
          ],  
          "characteristics": [  
            {  
              "table": "string",  
              "sys_id": {  
                "value": "string"  
              },  
              "attributes": {  
                "sys_id": {  
                  "value": "string"  
                },  
                "characteristic_value": {  
                  "value": ""  
                },  
                "characteristic": {  
                  "value": "string"  
                },  
                "characteristic_option": {  
                  "value": "string"  
                },  
                "sold_product": {  
                  "value": "string"  
                }  
              }  
            }  
          ]  
        }
    attributes Attributes of header record.
    "attributes": { 
            "name": { 
              "value": "string" 
            }

    Data type: Object

    attributes.<field_name> Attributes of the header record. For example, the account or contact, etc. May contain varying fields of the entity.
    
          "attributes": { 
            "name": { 
              "value": "string" 
            }

    Data type: Object

    attributes.<field_name>.value Value of the attribute belonging to the header record of an entity.

    Data type: String

    characteristics Characteristics of a line item.
    "characteristics": [ 
            { 
              "table": "string", 
              "sys_id": { 
                "value": "string" 
              }, 
              "attributes": { 
                "sys_id": { 
                  "value": "string" 
                }, 
                "characteristic_value": { 
                  "value": "" 
                }, 
                "characteristic": { 
                  "value": "string" 
                }, 
                "characteristic_option": { 
                  "value": "string" 
                }, 
                "sold_product": { 
                  "value": "string" 
                } 
              } 
            } 
          ] 
        } 
      ] 

    Data type: Array of objects

    characteristics.table Table name of the characteristic record of a Lead to Cash entity.

    Data type: String

    characteristics.sys_id Sys_id of a characteristic record.
    "sys_id": { 
                "value": "string" 
              }

    Data type: Object

    characteristics.sys_id.value The sys_id value of a characteristic record.

    Data type: String

    characteristics.attributes Attributes of characteristic record.
    "attributes": { 
                "sys_id": { 
                  "value": "string" 
                }

    Data type: Object

    characteristics.attributes.<field_name> Attributes of the characteristic record. For example, the name or characteristic value, etc. May contain varying characteristics based on the entity.
    { 
                  "value": "string" 
                }

    Data type: Object

    characteristics.attributes.<field_name>.value Value of the attribute belonging to the characteristic record of an entity.

    Data type: String

    items Contains an array of selected objects when context.isMultiSelect is set to true in getPrimitivesEPService().

    Data type: Array of objects

    {  
      "items": [ 
        { 
          "lineItems": [ 
            { 
              "table": "string", 
              "sys_id": { 
                "value": "string" 
              }, 
              "attributes": { 
                "name": { 
                  "value": "string" 
                }, 
                "account": { 
                  "value": "string" 
                } 
              }, 
              "lineItems": [ 
                { 
                  "table": "string", 
                  "sys_id": { 
                    "value": "string" 
                  }, 
                  "attributes": { 
                    "name": { 
                      "value": "string" 
                    }, 
                    "account": { 
                      "value": "string" 
                    } 
                  }, 
                  "lineItems": [], 
                  "characteristics": []
        } 
      ] 
    }
    lineItems Line items of an entity. For example, order line items, quote line items, etc.
    "lineItems": [ 
        { 
          "table": "string", 
          "sys_id": { 
            "value": "string" 
          }, 
          "attributes": { 
            "name": { 
              "value": "string" 
            }, 
            "account": { 
              "value": "string" 
            } 
          }

    Data type: Array

    lineItems.attributes Attributes of the line item record.
    "attributes": { 
            "name": { 
              "value": "string" 
            }
    }

    Data type: Object

    lineItems.attributes.<field_name> Attributes of the line item record. For example, the account or contact, etc. May contain varying fields based on the entity.
    "name": { 
              "value": "string" 
            }

    Data type: Object

    lineItems.attributes.<field_name>.value Value of the attribute belonging to the line item of an entity.

    Data type: String

    lineItems.LineItems Child line items of a parent line item.
    "lineItems": [ 
        { 
          "table": "sn_install_base_sold_product", 
          "sys_id": { 
            "value": "4e03cda2ec873110f87727ef5883a2cf" 
          }, 
          "attributes": { 
            "name": { 
              "value": "Quadplay Home Tech Hub Bundle" 
            }, 
            "account": { 
              "value": "9e2fd2ee11b43110f877366201dea674" 
            } 
          }
    ]

    Data type: Object

    lineItems.sys_id Sys_id of the line item record.
    "sys_id": { 
                "value": "string" 
              }, 

    Data type: Object

    lineItems.sys_id.value The sys_id value of the line item record.

    Data type: String

    lineItems.table Table name of the line item of a Lead to Cash entity.

    Data type: String

    sys_id Sys_id of the header record.
    "sys_id": { 
                "value": "string" 
              }

    Data type: Object

    sys_id.value The sys_id value of the header record.

    Data type: String

    table Table name of the header record of a Lead to Cash entity.

    Data type: String

    The example script below invokes the createInstance() method to load the data of a sold product, its entire hierarchy, and its characteristics.

    //Utility to invoke createInstance API 
    var util = new sn_l2c_core.PrimitiveUtil();  
     
    //Invoke extension point, picks an implementation based on sourceToTargetConfigID of a L2C flow, the Mapping Config ID  in "sn_l2c_core_entity_mapping" table. 
    var service = util.getPrimitivesEPService('sn_l2c_cust_flows_sp_to_order'); 
     
    //Invoke createInstance API with required params 
    var SPInstance = service.createInstance(null, '4e03cda2ec873110f87727ef5883a2cf'); 
     
    //Print the returned JSON 
    gs.info("SPInstance: "+JSON.stringify(SPInstance));  
     
    //The returned JSON can be used for subsequent methods of the flow such as delta(), effect() and commitInstance()

    Output:

    { 
      "lineItems": [ 
        { 
          "table": "sn_install_base_sold_product", 
          "sys_id": { 
            "value": "4e03cda2ec873110f87727ef5883a2cf" 
          }, 
          "attributes": { 
            "name": { 
              "value": "Quadplay Home Tech Hub Bundle" 
            }, 
            "account": { 
              "value": "9e2fd2ee11b43110f877366201dea674" 
            } 
          }, 
          "lineItems": [ 
            { 
              "table": "sn_install_base_sold_product", 
              "sys_id": { 
                "value": "9e0301e2ec873110f87727ef5883a23a" 
              }, 
              "attributes": { 
                "name": { 
                  "value": "Internet and OTT Bundle" 
                }, 
                "account": { 
                  "value": "9e2fd2ee11b43110f877366201dea674" 
                } 
              }, 
              "lineItems": [ 
              ], 
              "characteristics": [] 
            } 
          ], 
          "characteristics": [ 
            { 
              "table": "sn_prd_pm_product_characteristics", 
              "sys_id": { 
                "value": "8d669b6665ebf110f877d71ec56bf75c" 
              }, 
              "attributes": { 
                "sys_id": { 
                  "value": "8d669b6665ebf110f877d71ec56bf75c" 
                }, 
                "characteristic_value": { 
                  "value": "" 
                }, 
                "characteristic": { 
                  "value": "4f31999fd0a63110f8770dbf976be178" 
                }, 
                "characteristic_option": { 
                  "value": "4f31999fd0a63110f8770dbf976be179" 
                }, 
                "sold_product": { 
                  "value": "4e03cda2ec873110f87727ef5883a2cf" 
                } 
              } 
            } 
          ] 
        } 
      ] 
    } 

    Multi-select

    The following script demonstrates how to use isMultiSelect to invoke the createInstance() method and load the data of two sold products with their entire hierarchy and characteristics.

    //Utility to invoke createInstance API  
    var util = new sn_l2c_core.PrimitiveUtil();   
    
    //Set context variable isMultiSelect true to enable multi-select 
    var context = {"isMultiSelect": true}; 
    //Invoke extension point, picks an implementation based on sourceToTargetConfigID of a L2C flow, the Mapping Config ID  in “sn_l2c_core_entity_mapping” table.  
    var service = util.getPrimitivesEPService('sn_l2c_cust_flows_sp_to_order’, context);  
      
    //Multiple sold products selected  
    var selectedLineitems = '4e03cda2ec873110f87727ef5883a2cf,036a2349284d0210f877b68370fb2e93'; 
    
    //Invoke createInstance API with required params  
    var SPInstance = service.createInstance(null, selectedLineitems);  
      
    //Print the returned JSON  
    gs.info("SPInstance: "+JSON.stringify(SPInstance));   
      
    //The returned JSON can be used for subsequent APIs of the flow such as Delta, Effect and Commit Instance 

    Response:

    {  
      "items": [ 
        { 
          "lineItems": [ 
            { 
              "table": "sn_install_base_sold_product", 
              "sys_id": { 
                "value": "4e03cda2ec873110f87727ef5883a2cf" 
              }, 
              "attributes": { 
                "name": { 
                  "value": "Quadplay Home Tech Hub Bundle" 
                }, 
                "account": { 
                  "value": "9e2fd2ee11b43110f877366201dea674" 
                } 
              }, 
              "lineItems": [ 
                { 
                  "table": "sn_install_base_sold_product", 
                  "sys_id": { 
                    "value": "9e0301e2ec873110f87727ef5883a23a" 
                  }, 
                  "attributes": { 
                    "name": { 
                      "value": "Internet and OTT Bundle" 
                    }, 
                    "account": { 
                      "value": "9e2fd2ee11b43110f877366201dea674" 
                    } 
                  }, 
                  "lineItems": [], 
                  "characteristics": [] 
                } 
              ] 
            } 
          ] 
        }, 
        { 
          "lineItems": [ 
            { 
              "table": "sn_install_base_sold_product", 
              "sys_id": { 
                "value": "036a2349284d0210f877b68370fb2e93" 
              }, 
              "attributes": { 
                "name": { 
                  "value": "Quadplay Home Tech Hub Bundle" 
                }, 
                "account": { 
                  "value": "9e2fd2ee11b43110f877366201dea674" 
                } 
              }, 
              "lineItems": [ 
                { 
                  "table": "sn_install_base_sold_product", 
                  "sys_id": { 
                    "value": "4b6a2349284d0210f877b68370fb2e9c" 
                  }, 
                  "attributes": { 
                    "name": { 
                      "value": "Internet and OTT Bundle" 
                    }, 
                    "account": { 
                      "value": "9e2fd2ee11b43110f877366201dea674" 
                    } 
                  }, 
                  "lineItems": [], 
                  "characteristics": [] 
                } 
              ], 
              "characteristics": [] 
            } 
          ] 
        } 
      ] 
    }

    LeadtoCashCore - delta(Object sourceJSON, Object dirtyJSON, Object additionalParams)

    Compares the source and modified source JSON objects of a Lead to Cash entity and returns a JSON object that desrcribes any changes made to the source JSON, such as any additions, deletions, or modifications.

    Note:
    The LeadtoCashCore API requires you to first call the scripted extension point PrimitiveUtil() with the LeadtoCashCore - getPrimitivesEPService(String sourceToTargetConfigID, Object context) utility method to trigger the implementation before calling delta() in your script. Per each flow, get the service only once and use the same service for all LeadtoCashCore APIs.
    Table 5. Parameters
    Name Type Description
    sourceJSON Object The source JSON of the lead to cash entity.
    dirtyJSON Object The modified source JSON of the Lead to Cash entity.
    additionalParams Object Optional. Additional parameters to use. No additional parameters are available now but will in the future.
    Table 6. Returns
    Type Description
    JSON Object A JSON containing details of the entity record.

    Data type: Object

    { 
    "items": {  
      "lineItems": [  
        {  
          "table": "string",  
          "sys_id": {  
            "value": "number"  
          },  
          "attributes": {  
            "name": {  
              "value": "string"  
            },  
            "account": {  
              "value": "string"  
            }  
          },  
          "lineItems": [  
            {  
              "table": "string",  
              "sys_id": {  
                "value": "number"  
              },  
              "attributes": {  
                "name": {  
                  "value": "string"  
                },  
                "account": {  
                  "value": "string"  
                }  
              },  
              "lineItems": [  
                {  
                  "table": "string",  
                  "sys_id": {  
                    "value": "number"  
                  },  
                  "attributes": {  
                    "name": {  
                      "value": "string"  
                    },  
                    "account": {  
                      "value": "string"  
                    }  
                  },  
                  "lineItems": [],  
                  "characteristics": [],  
                  "_action": "string"  
                }  
              ],  
              "characteristics": [],  
              "_action": "string"  
            }  
          ],  
          "characteristics": [  
            {  
              "table": "string",  
              "sys_id": {  
                "value": "string"  
              },  
              "attributes": {  
                "characteristic_value": {  
                  "value": ""  
                },  
                "characteristic": {  
                  "value": "string"  
                },  
                "characteristic_option": {  
                  "value": "string"  
                },  
                "sold_product": {  
                  "value": "string"  
                },  
                "action": {  
                  "value": "string"  
                }  
              },  
              "_action": "string"  
            }  
          ],  
          "_action": "string"  
        }  
      ]  
    }
    _action The action applied to the source JSON. Possible values:
    • add- information was added to the source JSON.
    • change- information was updated in the source JSON.
    • disconnect- information was disconnected from the source JSON.
    • no-change- no change occurred on the source JSON.
    attributes Attributes of header record.
    "attributes": { 
            "name": { 
              "value": "string" 
            }

    Data type: Object

    attributes.<field_name> Attributes of the header record. For example, the account or contact, etc. May contain varying fields of the entity.
    
          "attributes": { 
            "name": { 
              "value": "string" 
            }

    Data type: Object

    attributes.<field_name>.value Value of the attribute belonging to the header record of an entity.

    Data type: String

    characteristics._action The action applied to the characteristic. Possible values:
    • add- information was added to the characteristic.
    • change- information was updated on the characteristic.
    • disconnect- information was disconnected from the characteristic.
    • no-change- no change occurred to the characteristic.
    characteristics.attributes Attributes of characteristic record.
    "attributes": { 
                    "sys_id": { 
                    "value": "string" 
                    }

    Data type: Object

    characteristics.attributes.<field_name> Attributes of the characteristic record. For example, the name or characteristic value, etc. May contain varying characteristics based on the entity.
    { 
                    "value": "string" 
                    }

    Data type: Object

    characteristics.attributes.<field_name>.value Value of the attribute belonging to the characteristic record of an entity.

    Data type: String

    characteristics.sys_id Sys_id of a characteristic record.
    "sys_id": { 
                    "value": "string" 
                    }

    Data type: Object

    characteristics.sys_id.value The sys_id value of a characteristic record.

    Data type: String

    characteristics.table Table name of the characteristic record of a Lead to Cash entity.

    Data type: String

    lineItems Line items of an entity. For example, order line items, quote line items, etc.
    "lineItems": [ 
                { 
                  "table": "string", 
                  "sys_id": { 
                    "value": "number" 
                  }, 
                  "attributes": { 
                    "name": { 
                      "value": "string" 
                    }, 
                    "account": { 
                      "value": "string" 
                    } 
                  }, 
                  "lineItems": [], 
                  "characteristics": [], 
                  "_action": "string" 
                } 
              ], 
              "characteristics": [], 
              "_action": "string" 
            } 
          ], 

    Data type: Array

    lineItems._action The action applied to the line item in the source JSON. Possible values:
    • add- information was added to the line item.
    • change- information was updated the line item.
    • disconnect- information was disconnected from the line item.
    • no-change- no change occurred on the line item.
    lineItems.attributes Attributes of the line item record.
    "attributes": { 
            "name": { 
              "value": "string" 
            }
    }

    Data type: Object

    lineItems.table Table name of the line item of a Lead to Cash entity.

    Data type: String

    lineItems.sys_id Sys_id of the line item record.
    "sys_id": { 
                "value": "string" 
              }, 

    Data type: Object

    lineItems.sys_id.value The sys_id value of the line item record.

    Data type: String

    lineItems.attributes.<field_name> Attributes of the line item record. For example, the account or contact, etc. May contain varying fields based on the entity.
    "name": { 
              "value": "string" 
            }

    Data type: Object

    lineItems.attributes.<field_name>.value Value of the attribute belonging to the line item of an entity.

    Data type: String

    lineItems.LineItems Child line items of a parent line item.
    "lineItems": [ 
        { 
          "table": "sn_install_base_sold_product", 
          "sys_id": { 
            "value": "4e03cda2ec873110f87727ef5883a2cf" 
          }, 
          "attributes": { 
            "name": { 
              "value": "Quadplay Home Tech Hub Bundle" 
            }, 
            "account": { 
              "value": "9e2fd2ee11b43110f877366201dea674" 
            } 
          }
    ]

    Data type: Object

    lineItems.characteristics Characteristics of a line item.
    "characteristics": [ 
            { 
              "table": "string", 
              "sys_id": { 
                "value": "string" 
              }, 
              "attributes": { 
                "characteristic_value": { 
                  "value": "" 
                }, 
                "characteristic": { 
                  "value": "string" 
                }, 
                "characteristic_option": { 
                  "value": "string" 
                }, 
                "sold_product": { 
                  "value": "string" 
                }, 
                "action": { 
                  "value": "string" 
                } 
              }, 
              "_action": "string" 
            } 
          ], 

    Data type: Array

    sys_id Sys_id of the header record.
    "sys_id": { 
                "value": "string" 
              }

    Data type: Object

    sys_id.value The sys_id value of the header record.

    Data type: String

    table Table name of the header record of a Lead to Cash entity.

    Data type: String

    The following example demonstrates how to call the delta() method by first calling the PrimitiveUtil utility method and getPrimitiesEPService(), and then providing the source and target JSON objects.

    //Utility to invoke Delta API 
    var util = new sn_l2c_core.PrimitiveUtil();  
     
    //Invoke extension point, picks an implementation based on sourceToTargetConfigID of a L2C flow, the Mapping Config ID  in “sn_l2c_core_entity_mapping” table. 
    var service = util.getPrimitivesEPService('sp_order_macd'); 
     
    //Invoke delta API with required params 
    // sourceJSON can be the output of createInstance or null 
    //dirtyJSON is the modified sourceJSON 
    var deltaOutput= service.delta(sourceJSON, dirtyJSON);  
     
    //Print the returned JSON 
    gs.info(" deltaOutput: "+JSON.stringify(deltaOutput));  
     
    //The returned JSON can be used for subsequent APIs of the flow such as Effect and Commit Instance

    The output JSON shows that several line items were added to the sold base product:

    { 
      "lineItems": [ 
        { 
          "table": "sn_install_base_sold_product", 
          "sys_id": { 
            "value": "-1" 
          }, 
          "attributes": { 
            "name": { 
              "value": "Quadplay Home Tech Hub Bundle" 
            }, 
            "account": { 
              "value": "9e2fd2ee11b43110f877366201dea674" 
            } 
          }, 
          "lineItems": [ 
            { 
              "table": "sn_install_base_sold_product", 
              "sys_id": { 
                "value": "-1" 
              }, 
              "attributes": { 
                "name": { 
                  "value": "Internet and OTT Bundle" 
                }, 
                "account": { 
                  "value": "9e2fd2ee11b43110f877366201dea674" 
                } 
              }, 
              "lineItems": [ 
                { 
                  "table": "sn_install_base_sold_product", 
                  "sys_id": { 
                    "value": "-1" 
                  }, 
                  "attributes": { 
                    "name": { 
                      "value": "Solana Sports streaming channel" 
                    }, 
                    "account": { 
                      "value": "9e2fd2ee11b43110f877366201dea674" 
                    } 
                  }, 
                  "lineItems": [], 
                  "characteristics": [], 
                  "_action": "add" 
                } 
              ], 
              "characteristics": [], 
              "_action": "add" 
            } 
          ], 
          "characteristics": [ 
            { 
              "table": "sn_prd_pm_product_characteristics", 
              "sys_id": { 
                "value": "-1" 
              }, 
              "attributes": { 
                "characteristic_value": { 
                  "value": "" 
                }, 
                "characteristic": { 
                  "value": "4f31999fd0a63110f8770dbf976be178" 
                }, 
                "characteristic_option": { 
                  "value": "4f31999fd0a63110f8770dbf976be179" 
                }, 
                "sold_product": { 
                  "value": "4e03cda2ec873110f87727ef5883a2cf" 
                }, 
                "action": { 
                  "value": "add" 
                } 
              }, 
              "_action": "add" 
            } 
          ], 
          "_action": "add" 
        } 
      ] 
    } 

    Multi-select

    The following example shows how to form the multi-select delta() method by first calling PrimitiveUtil and getPrimitivesEPService and then providing the source and target JSON objects for multiple line or header IDs. Per each flow, get the service only once and use the same service for all the LeadtoCashCore methods.

    /Utility to invoke Delta API  
    var util = new sn_l2c_core.PrimitiveUtil();   
    
    //Set context variable isMultiSelect true to enable multi-select 
    var context = {"isMultiSelect": true}; 
     
    //Invoke extension point, picks an implementation based on sourceToTargetConfigID of a L2C flow, the Mapping Config ID  in “sn_l2c_core_entity_mapping” table.  
    var service = util.getPrimitivesEPService(‘sn_l2c_cust_flows_sp_to_order’, context);  
      
    //Invoke delta API with required params  
    // sourceJSON can be the output of createInstance for multiple lineIDs or headerIDs or null  
    //dirtyJSON is the modified sourceJSON  
    var deltaOutput= service.delta(sourceJSON, dirtyJSON);   
      
    //Print the returned JSON  
    gs.info(" deltaOutput: "+JSON.stringify(deltaOutput));   
      
    //The returned JSON can be used for subsequent APIs of the flow such as Effect and Commit Instance

    The output JSON shows that several line items were added to the sold base product:

    { 
      "items": [ 
        { 
          "lineItems": [ 
            { 
              "table": "sn_install_base_sold_product", 
              "sys_id": { 
                "value": "4e03cda2ec873110f87727ef5883a2cf" 
              }, 
              "attributes": { 
                "name": { 
                  "value": "Quadplay Home Tech Hub Bundle" 
                }, 
                "account": { 
                  "value": "9e2fd2ee11b43110f877366201dea674" 
                } 
              }, 
              "lineItems": [ 
                { 
                  "table": "sn_install_base_sold_product", 
                  "sys_id": { 
                    "value": "9e0301e2ec873110f87727ef5883a23a" 
                  }, 
                  "attributes": { 
                    "name": { 
                      "value": "Internet and OTT Bundle" 
                    }, 
                    "account": { 
                      "value": "9e2fd2ee11b43110f877366201dea674" 
                    } 
                  }, 
                  "lineItems": [], 
                  "characteristics": [], 
                  "_action": "disconnect" 
                } 
              ], 
              "characteristics": [], 
              "_action": "disconnect" 
            } 
          ] 
        }, 
        { 
          "lineItems": [
            { 
              "table": "sn_install_base_sold_product", 
              "sys_id": { 
                "value": "036a2349284d0210f877b68370fb2e93" 
              }, 
              "attributes": { 
                "name": { 
                  "value": "Quadplay Home Tech Hub Bundle" 
                }, 
                "account": { 
                  "value": "9e2fd2ee11b43110f877366201dea674" 
                } 
              }, 
              "lineItems": [ 
                { 
                  "table": "sn_install_base_sold_product", 
                  "sys_id": { 
                    "value": "4b6a2349284d0210f877b68370fb2e9c" 
                  },
                  "attributes": { 
                    "name": { 
                      "value": "Internet and OTT Bundle" 
                    }, 
                    "account": { 
                      "value": "9e2fd2ee11b43110f877366201dea674" 
                    } 
                  }, 
                  "lineItems": [], 
                  "characteristics": [], 
                  "_action": "disconnect" 
                } 
              ], 
              "characteristics": [], 
              "_action": "disconnect" 
            } 
          ] 
        } 
      ] 
    }

    LeadtoCashCore - effect(Object sourceJSON, Object targetJSON, Object additionalParams)

    Transforms and applies the source JSON structure of a given entity to the target JSON of another entity. You can then commit the changed entity to the database using the commitInstance() method.

    You can use the output JSON of the delta() method in the effect() request. Then, commit any effect() JSON output to the database using the commitInstance() to complete the Lead to Cash workflow.

    Note:
    The LeadtoCashCore script include requires you to first call the scripted extension point PrimitiveUtil() with the LeadtoCashCore - getPrimitivesEPService(String sourceToTargetConfigID, Object context) utility method to trigger the implementation before calling effect() in your script. Per each flow, get the service only once and use the same service for all LeadtoCashCore methods.
    Table 7. Parameters
    Name Type Description
    sourceJSON Object JSON containing details of the source entity.
    targetJSON Object JSON containing details of the target entity.
    additionalParams Object Optional. Specifies additional parameters to use. No additional parameters are available now but will in the future.
    Table 8. Returns
    Type Description
    JSON Object Change that occurred and was applied from the source to target entity JSON objects at each of the object, header line, child lines, and characteristic levels of the Lead to Cash entity.
    Possible values:
    • INSERT - Information was added between the source and target JSON structures.
    • UPDATE - Information was modified between the source and JSON structures.
    • DELETE - Information was removed between the source and target JSON structures.
    • NO_CHANGE – No change occurred between the source and target JSON structures.
    The following example shows how to apply transformation logic using the output of the delta() method:
    Note:
    The same script is applicable for both single select and multi-select use cases, as just the source JSON format changes and the output remains the same for both. For multi-select use cases, a single header is created with all the line items added to the same header.
    //Utility to invoke effect API 
    var util = new sn_l2c_core.PrimitiveUtil();  
     
    //Invoke extension point, picks an implementation based on sourceToTargetConfigID of a L2C flow, the Mapping Config ID  in “sn_l2c_core_entity_mapping” table. 
    var service = util.getPrimitivesEPService('sp_order_macd'); 
     
    //Invoke effect API with required params 
    var effectOutput = service.effect(deltaOutput, null); 
     
    //Print the returned JSON 
    gs.info("effectOutput: " + JSON.stringify(effectOutput)); 
     
    //The returned JSON can be used in the subsequent commitInstance() method.

    Output:

    { 
      "sys_id": "-1", 
      "table": "sn_ind_tmt_orm_order", 
      "_glide_action": "INSERT", 
      "_source_object": {}, 
      "lineItems": [ 
        { 
          "sys_id": "-1", 
          "table": "sn_ind_tmt_orm_order_line_item", 
          "attributes": { 
            "account": { 
              "value": "9e2fd2ee11b43110f877366201dea674" 
            }, 
            "short_description": { 
              "value": "Quadplay Home Tech Hub Bundle" 
            } 
          }, 
          "_glide_action": "INSERT", 
          "_source_object": { 
            "sys_id": "-1", 
            "table": "sn_install_base_sold_product" 
          }, 
          "lineItems": [ 
            { 
              "sys_id": "-1", 
              "table": "sn_ind_tmt_orm_order_line_item", 
              "attributes": { 
                "account": { 
                  "value": "9e2fd2ee11b43110f877366201dea674" 
                }, 
                "short_description": { 
                  "value": "Internet and OTT Bundle" 
                } 
              }, 
              "_glide_action": "INSERT", 
              "_source_object": { 
                "sys_id": "-1", 
                "table": "sn_install_base_sold_product" 
              }, 
              "lineItems": [ 
                { 
                  "sys_id": "-1", 
                  "table": "sn_ind_tmt_orm_order_line_item", 
                  "attributes": { 
                    "account": { 
                      "value": "9e2fd2ee11b43110f877366201dea674" 
                    }, 
                    "short_description": { 
                      "value": "Solana Sports streaming channel" 
                    } 
                  }, 
                  "_glide_action": "INSERT", 
                  "_source_object": { 
                    "sys_id": "-1", 
                    "table": "sn_install_base_sold_product" 
                  }, 
                  "lineItems": [], 
                  "characteristics": [] 
                } 
              ], 
              "characteristics": [] 
            } 
          ], 
          "characteristics": [ 
            { 
              "sys_id": "-1", 
              "table": "sn_ind_tmt_orm_order_characteristic_value", 
              "attributes": { 
                "characteristic_option": { 
                  "value": "4f31999fd0a63110f8770dbf976be179" 
                }, 
                "characteristic": { 
                  "value": "4f31999fd0a63110f8770dbf976be178" 
                }, 
                "characteristic_option_value": { 
                  "value": "" 
                } 
              }, 
              "_glide_action": "INSERT", 
              "_source_object": { 
                "sys_id": "-1", 
                "table": "sn_prd_pm_product_characteristics" 
              } 
            } 
          ] 
        } 
      ] 
    } 

    LeadtoCashCore - getPrimitivesEPService(String sourceToTargetConfigID, Object context)

    Triggers the PrimitiveUtil() utility method.

    To use any of the available methods in the LeadtoCashCore script include, you must first always call the scripted extension point PrimitiveUtil() in your script with the getPrimitivesEPService() utility method to trigger the implementation.

    Table 9. Parameters
    Name Type Description
    sourceToTargetConfigID String Mapping config ID for the source-to-target mapping. Located in the Lead To Cash Entity Mapping [sn_l2c_core_entity_mapping] table.
    context Object Optional. Additional parameter options for displaying attribute values and for invoking more than one instance at a time.
    {
        "context": [
            {
                "loadDisplayValue": "Boolean",
                "isMultiSelect": "Boolean"
                },
      ]
    }
    context.loadDisplayValue Boolean Optional. Flag that indicates whether to load the display value for each attribute.
    Valid values:
    • true: Enables the loading of an attribute's display value.
    • false: Does not enable the loading of an attribute's display value.

    Default: false

    context.isMultiSelect Boolean Optional. Flag that indicates whether to pass multiple entities as input to create the instance.
    Valid values:
    • true: Enables the passing of multiple entities as input. When true, you can pass multiple line items in a comma-separated list.
    • false: Eoes not enable the passing of multiple entities as input. Only one input may be passed in the API script.

    The multiSelect feature is only applicable to the createInstance(), delta(), and effect() methods.

    Default: false

    Table 10. Returns
    Type Description
    None

    The following example invokes PrimitiveUtil() and picks an implementation based on sn_l2c_cust_flows_sp_to_order, which is a Mapping Config ID in the Lead To Cash Entity Mapping [sn_l2c_core_entity_mapping] table.

    //Utility to invoke createInstance API  
    var util = new sn_l2c_core.PrimitiveUtil(); 
    var context = {"isMultiSelect": true}; // Set the context.isMultiSelect parameter as true to enable multi-select use cases
    
    //Invokes the extension point and specifies an implementation based on sourceToTargetConfigID of a L2C flow.  
    var service = util.getPrimitivesEPService('sn_l2c_cust_flows_sp_to_order’, context)