{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":837,"path":"api-reference/server-api-reference/LeadAPIHelperOOBAPI.md","title":"LeadAPIHelperOOB - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# LeadAPIHelperOOB- Scoped\n\nThe 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.\n\nIf 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.\n\nThis 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.\n\nFor additional information on Lead Management, see [Using Lead Management](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/order-management/lead-management-using.md).\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## LeadAPIHelperOOB - getJSONFromGR\\(GlideRecord gr, Array fields\\)\n\nConverts 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.\n\n<table id=\"table_wfp_p1z_ydc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ngr\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nGlideRecord object to convert to a JSON object.\n\n</td></tr><tr><td>\n\nfields\n\n</td><td>\n\nArray\n\n</td><td>\n\nOptional. 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\"]`\n\n**Note:**\n\nIf the **fields** parameter is null or contains the value `\"lead_line_items\"`, the method fetches each associated line item record, including all fields of the line item.\n\nThis 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.\n\nDefault: All lead record fields are included in the JSON object.\n\n</td></tr></tbody>\n</table><table id=\"table_xfp_p1z_ydc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nJSON object\n\n</td><td>\n\nJSON 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.\n\n</td></tr></tbody>\n</table>The following code example shows where to add your custom code for the getJsonFromGR\\(\\) method in the LeadAPIHelper script include.\n\n```\nvar LeadAPIHelper = Class.create(); \nLeadAPIHelper.prototype = Object.extendsObject(LeadAPIHelperOOB, {\n\n// Define overriding functions here\ngetJSONFromGR: function(gr, fields) {\n\n// Add your custom code here\n},\n\ntype: 'LeadAPIHelper'\n});\n```\n\n## LeadAPIHelperOOB - getLeadsJSON\\(GlideRecord leadsGr, Array fields\\)\n\nConverts 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.\n\n<table id=\"table_d41_qvy_ydc\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nleadsGr\n\n</td><td>\n\nGlideRecord\n\n</td><td>\n\nGlideRecord object containing the lead records to convert to JSON.Table: Lead \\[sn\\_lead\\_mgmt-core\\_lead\\]\n\n</td></tr><tr><td>\n\nfields\n\n</td><td>\n\nArray\n\n</td><td>\n\nComma-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\"]`\n\n**Note:**\n\nIf the **fields** parameter is null or contains the value `\"lead_line_items\"`, the method fetches each associated line item record, including all fields of the line item.\n\nThis 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.\n\n</td></tr></tbody>\n</table><table id=\"table_e41_qvy_ydc\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nArray of JSON objects\n\n</td><td>\n\nEach 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.\n\n</td></tr></tbody>\n</table>The following code example shows where to add your custom code for the getLeadsJson\\(\\) method in the LeadAPIHelper script include.\n\n```\nvar LeadAPIHelper = Class.create();\nLeadAPIHelper.prototype = Object.extendsObject(LeadAPIHelperOOB, { \n\n// Define overriding functions here \ngetLeadsJson: function(leadsGR, fields) {\n\n// Add your custom code here\n}, \n\ntype: 'LeadAPIHelper' \n}); \n```\n\n## LeadAPIHelperOOB - getTransformedLeadObject\\(Object leadObject\\)\n\nTransforms the specified lead object.\n\nThis transformation includes:\n\n-   Removing ignored fields.\n-   Converting reference fields to their  associated values, such as a sys\\_id.\n-   Combining work notes texts into a comma-separated string.\n-   Validating the account, contact, and consumer fields. The values of account, contact, and consumer are ignored if both account and consumer contain values.\n\n|Name|Type|Description|\n|----|----|-----------|\n|leadObject|Object|Lead object to transform. This object contains details of the lead and its related lead line items.|\n\n|Type|Description|\n|----|-----------|\n|Object|Transformed lead object.|\n\nThe following code example shows where to add your custom code for the getTransformedLeadObject\\(\\) method in the LeadAPIHelper script include.\n\n```\nvar LeadAPIHelper = Class.create();\n\nLeadAPIHelper.prototype = Object.extendsObject(LeadAPIHelperOOB, {\n\n// Define overriding functions here \ngetTransformedLeadObject: function(leadObject) { \n\n// Add your custom code here\n}, \n\ntype: 'LeadAPIHelper'\n}); \n```\n\n"}}