LeadAPIHelperOOB - Scoped
The LeadAPIHelperOOB script include provides helper methods called by the lead REST API to perform various functions, such as converting a set of lead records from a GlideRecord object into a JSON array or JSON object and transforming fields within a lead object.
If you want to customize these helper functions, override the methods in this script include in the LeadAPIHelper script include. The names of the methods that you are overriding in the LeadAPIHelper script include must be the same as those in the LeadAPIHelperOOB script include file.
This API is provided within the sn_lead_mgmt_core namespace. To access the API, the Lead Management Data Model (sn_lead_mgmt_core) plugin must be activated on the instance, and the calling
user must have the sn_lead_mgmt_core.lead_integrator role.
For additional information on Lead Management, see Using Lead Management.
LeadAPIHelperOOB - getJSONFromGR(GlideRecord gr, Array fields)
Converts a GlideRecord object into a JSON object. This method iterates over the fields of the GlideRecord, checks their types, and appropriately formats their values into a JSON-compatible structure.
| Name | Type | Description |
|---|---|---|
| gr | GlideRecord | GlideRecord object to convert to a JSON object. |
| fields | Array | Optional. Comma-separated field names to include in the JSON object. These names must exactly match the names in the lead record. For example: ["account", "first_name", "do_not_call", "lead_line_items"]Note: If the fields parameter is null or contains the value This method only supports converting individual fields from the Lead [sn_lead_mgmt_core_lead] table, not the Lead Line Item [sn_lead_mgmt_core_lead_line_item] table. If you specify a specific field from the Lead Line Item table, it is ignored. Default: All lead record fields are included in the JSON object. |
| Type | Description |
|---|---|
| JSON object | JSON object that contains the fields from the specified GlideRecord. Each field in the GlideRecord is converted to a key-value pair. Special handling is applied for reference fields, choice fields, date-time fields, and other specific data types to ensure they are correctly formatted. |
The following code example shows where to add your custom code for the getJsonFromGR() method in the LeadAPIHelper script include.
var LeadAPIHelper = Class.create();
LeadAPIHelper.prototype = Object.extendsObject(LeadAPIHelperOOB, {
// Define overriding functions here
getJSONFromGR: function(gr, fields) {
// Add your custom code here
},
type: 'LeadAPIHelper'
});
LeadAPIHelperOOB - getLeadsJSON(GlideRecord leadsGr, Array fields)
Converts a set of lead records from a GlideRecord object to a JSON array. You must specify the lead record fields that you want included in the JSON array.
| Name | Type | Description |
|---|---|---|
| leadsGr | GlideRecord | GlideRecord object containing the lead records to convert to JSON. Table: Lead [sn_lead_mgmt-core_lead] |
| fields | Array | Comma-separated field names to include in the JSON object. These names must exactly match the names in the lead record. For example: ["account", "first_name", "do_not_call", "lead_line_items"]Note: If the fields parameter is null or contains the value This method only supports converting individual fields from the Lead [sn_lead_mgmt_core_lead] table, not the Lead Line Item [sn_lead_mgmt_core_lead_line_item] table. If you specify a specific field from the Lead Line Item table, it is ignored. |
| Type | Description |
|---|---|
| Array of JSON objects | Each object represents a lead containing the specified fields. If applicable, it also includes an array of lead line item objects for every lead. Each field in the GlideRecord is converted to a key-value pair. Special handling is applied for reference fields, choice fields, date-time fields, and other specific data types to ensure they are correctly formatted. |
The following code example shows where to add your custom code for the getLeadsJson() method in the LeadAPIHelper script include.
var LeadAPIHelper = Class.create();
LeadAPIHelper.prototype = Object.extendsObject(LeadAPIHelperOOB, {
// Define overriding functions here
getLeadsJson: function(leadsGR, fields) {
// Add your custom code here
},
type: 'LeadAPIHelper'
});
LeadAPIHelperOOB - getTransformedLeadObject(Object leadObject)
Transforms the specified lead object.
- Removing ignored fields.
- Converting reference fields to their associated values, such as a sys_id.
- Combining work notes texts into a comma-separated string.
- Validating the account, contact, and consumer fields. The values of account, contact, and consumer are ignored if both account and consumer contain values.
| Name | Type | Description |
|---|---|---|
| leadObject | Object | Lead object to transform. This object contains details of the lead and its related lead line items. |
| Type | Description |
|---|---|
| Object | Transformed lead object. |
The following code example shows where to add your custom code for the getTransformedLeadObject() method in the LeadAPIHelper script include.
var LeadAPIHelper = Class.create();
LeadAPIHelper.prototype = Object.extendsObject(LeadAPIHelperOOB, {
// Define overriding functions here
getTransformedLeadObject: function(leadObject) {
// Add your custom code here
},
type: 'LeadAPIHelper'
});