{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":838,"path":"api-reference/server-api-reference/LeadAPIProcessUtilOOBAPI.md","title":"LeadAPIProcessUtilOOB - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# LeadAPIProcessUtilOOB- Scoped\n\nThe LeadAPIProcessUtilOOB script include provides methods that are called by the lead REST API to retrieve lead records and their associated lead line item records.\n\nIf you want to customize how lead records are retrieved when the [lead API](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-apis/lead-api.md) methods are called, override the methods in this script include in the LeadAPIProcessUtil script include. The names of the methods that you are overriding in the LeadAPIProcessUtil script include must be the same as those in the LeadAPIProcessUtilOOB 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## LeadAPIProcessUtilOOB - processCreateLead \\(Object requestBody\\)\n\nProcesses the request body and creates a lead and all its associated line items, based on the passed parameters.\n\nRecords are inserted in the following tables:\n\n-   Lead \\[sn\\_lead\\_mgmt\\_core\\_lead\\]\n-   Lead Line Item \\[sn\\_lead\\_mgmt\\_core\\_lead\\_line\\_item\\]\n\n<table id=\"table_sxx_crr_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\nrequestBody\n\n</td><td>\n\nObject\n\n</td><td>\n\nRequest body of the lead and its related lead line items to create.For details on the contents of this object, see [lead - POST /sn\\_lead\\_mgmt\\_core/lead](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-apis/lead-api.md).\n\n</td></tr></tbody>\n</table><table id=\"table_txx_crr_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\nDetails of the saved lead and lead line item records.Data type: Object\n\n```\n{\n  \"body\": {Object},\n  \"status\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;JSONobject&gt;.body\n\n</td><td>\n\nResponse body.Successful response: All fields within the requested lead record and all fields in the associated lead line item records. For a description of the fields returned, refer to [lead - POST /sn\\_lead\\_mgmt\\_core/lead](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-apis/lead-api.md).\n\nError response: List of errors detected when trying to process the request. These error messages are defined in the LeadAPIConstants script include.\n\nData type: Object\n\n</td></tr><tr><td>\n\n&lt;JSONobject&gt;.status\n\n</td><td>\n\nResponse status code.These status codes are defined in the LeadAPIConstants script include.\n\nData type: String\n\n</td></tr></tbody>\n</table>The following code example shows where to add your custom code for the processCreateLead\\(\\) method in the LeadAPIProcessUtil script include.\n\n```\nvar LeadAPIProcessUtil = Class.create(); \n\nLeadAPIProcessUtil.prototype = Object.extendsObject(LeadAPIProcessUtilOOB, { \n\n// Define overriding functions here \n\nprocessCreateLead: function(requestBody) { \n// Add your custom code \n}, \n\ntype: 'LeadAPIProcessUtil' \n\n}); \n```\n\n## LeadAPIProcessUtilOOB - processGetAllLeads \\(Object queryParams, String requestUrl\\)\n\nRetrieves all lead records and associated line item records based on the passed-in filter criteria. This method returns all fields within the associated records.\n\nRecord details are fetched from the following tables:\n\n-   Lead \\[sn\\_lead\\_mgmt\\_core\\_lead\\]\n-   Lead Line Item \\[sn\\_lead\\_mgmt\\_core\\_lead\\_line\\_item\\]\n\n<table id=\"table_igt_klr_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\nqueryParams\n\n</td><td>\n\nObject\n\n</td><td>\n\nObject containing the query parameters to apply when retrieving the lead records. These are the query parameters passed in the [lead - GET /sn\\_lead\\_mgmt\\_core/lead](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-apis/lead-api.md) endpoint.For example:\n\n```\n{\n  \"sysparm_fields\":[\"first_name,last_name,sys_id,lead_line_items\"],\n  \"sysparm_query\":[\"lead_type=new_business\"],\n  \"sysparm_offset\":[\"2\"],\"sysparm_limit\":[\"25\"]\n}\n```\n\n</td></tr><tr><td>\n\nrequestUrl\n\n</td><td>\n\nString\n\n</td><td>\n\nRequest URL. Pass this URL when you are processing a paginated response so that the method has the links to all of the pages in the response.\n\n</td></tr></tbody>\n</table><table id=\"table_jgt_klr_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\nDetails of the requested lead and lead line item records.Data type: Object\n\n```\n{\n  \"body\": [Array],\n  \"contentRange\": \"String\",\n  \"links\": \"String\", \n  \"status\": \"String\",\n  \"totalCount\": \"Number\" \n}\n```\n\nIf an errors occur while processing the request, the JSON object only contains the `body` and `status` parameters.\n\n</td></tr><tr><td>\n\n&lt;JSONobject&gt;.body\n\n</td><td>\n\nResponse body.Successful response: An array of objects with each object containing a lead record and all associated lead line item records. All fields within the requested lead record and all fields in the associated lead line item records are returned. For a description of the fields returned, refer to [lead - GET /sn\\_lead\\_mgmt\\_core/lead](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-apis/lead-api.md).\n\nError response: List of errors detected when trying to process the request. These error messages are defined in the LeadAPIConstants script include.\n\nData type: Array of Objects\n\n</td></tr><tr><td>\n\n&lt;JSONobject&gt;.contentRange\n\n</td><td>\n\nRange of the content returned in a paginated call. For example: If offset=2 and limit=3, the value of this parameter is items 3-5.\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;JSONobject&gt;.links\n\n</td><td>\n\nIn the case of a paginated response, comma-separated links to each page contained in the response.For example:\n\n```\n<https://servicenow-instance/api/sn_lead_mgmt_core/lead?sysparm_offset=0&sysparm_limit=20>;rel=\"self\",\n<https://servicenow-instance/api/sn_lead_mgmt_core/lead?sysparm_offset=20&sysparm_limit=20>;rel=\"last\",\n<https://servicenow-instance/api/sn_lead_mgmt_core/lead?sysparm_offset=20&sysparm_limit=20>;rel=\"next\"\n```\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;JSONobject&gt;.status\n\n</td><td>\n\nResponse status code.These status codes are defined in the LeadAPIConstants script include.\n\nData type: String\n\n</td></tr><tr><td>\n\n&lt;JSONobject&gt;.totalCount\n\n</td><td>\n\nTotal number of lead records returned by the method.Data type: Number \\(Integer\\)\n\n</td></tr></tbody>\n</table>The following code example shows where to add your custom code for the processGetAllLeads\\(\\) method in the LeadAPIProcessUtil script include.\n\n```\nvar LeadAPIProcessUtil = Class.create(); \n\nLeadAPIProcessUtil.prototype = Object.extendsObject(LeadAPIProcessUtilOOB, { \n\n// Define overriding functions here \n\nprocessGetAllLeads: function(queryParams, requestUrl) { \n// Add your custom code here \n}, \n\ntype: 'LeadAPIProcessUtil' \n}); \n```\n\n## LeadAPIProcessUtilOOB - processGetLeadById \\(String id\\)\n\nRetrieves the specified lead record and its associated line item records. This method returns all fields within the associated records.\n\nRecord details are fetched from the following tables:\n\n-   Lead \\[sn\\_lead\\_mgmt\\_core\\_lead\\]\n-   Lead Line Item \\[sn\\_lead\\_mgmt\\_core\\_lead\\_line\\_item\\]\n\n<table id=\"table_fvz_qcl_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\nid\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the lead record to retrieve.Table: Lead \\[sn\\_lead\\_mgmt\\_core\\_lead\\]\n\n</td></tr></tbody>\n</table><table id=\"table_gvz_qcl_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\nDetails of the requested lead and lead line item records.Data type: Object\n\n```\n{\n  \"body\": {Object},\n  \"status\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;JSONobject&gt;.body\n\n</td><td>\n\nResponse body.Successful response: All fields within the requested lead record and all fields in the associated lead line item records. For a description of the fields returned, refer to [lead - GET /sn\\_lead\\_mgmt\\_core/lead/\\{sys\\_id\\}](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-apis/lead-api.md).\n\nError response: List of errors detected when trying to process the request. These error messages are defined in the LeadAPIConstants script include.\n\nData type: Object\n\n</td></tr><tr><td>\n\n&lt;JSONobject&gt;.status\n\n</td><td>\n\nResponse status code.These status codes are defined in the LeadAPIConstants script include.\n\nData type: String\n\n</td></tr></tbody>\n</table>The following code example shows where to add your custom code for the processGetLeadById\\(\\) method in the LeadAPIProcessUtil script include.\n\n```\nvar LeadAPIProcessUtil = Class.create(); \n\nLeadAPIProcessUtil.prototype = Object.extendsObject(LeadAPIProcessUtilOOB, { \n\n// Define overriding functions here\n\nprocessGetLeadById: function(id) { \n  // Add your custom code here\n}, \n\ntype: 'LeadAPIProcessUtil' \n\n}); \n```\n\n## LeadAPIProcessUtilOOB - processUpdateLead \\(Object requestBody, String id\\)\n\nProcesses the request body and updates the specified lead and all its associated line items, based on the passed parameters.\n\nRecords are updated in the following tables:\n\n-   Lead \\[sn\\_lead\\_mgmt\\_core\\_lead\\]\n-   Lead Line Item \\[sn\\_lead\\_mgmt\\_core\\_lead\\_line\\_item\\]\n\n<table id=\"table_n24_k5r_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\nrequestBody\n\n</td><td>\n\nObject\n\n</td><td>\n\nRequest body of the lead and its related lead line item fields to update.For details on the contents of this object, see [lead - PATCH /sn\\_lead\\_mgmt\\_core/lead/\\{sys\\_id\\}](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-apis/lead-api.md).\n\n</td></tr><tr><td>\n\nid\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of the lead record to update.Table: Lead \\[sn\\_lead\\_mgmt\\_core\\_lead\\]\n\n</td></tr></tbody>\n</table><table id=\"table_o24_k5r_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\nDetails of the saved lead and lead line item records.Data type: Object\n\n```\n{\n  \"body\": {Object},\n  \"status\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\n&lt;JSONobject&gt;.body\n\n</td><td>\n\nResponse body.Successful response: All fields of the updated lead record and all fields in the associated lead line item records \\(updated or not\\). For a description of the fields returned, refer to [lead - PATCH /sn\\_lead\\_mgmt\\_core/lead/\\{sys\\_id\\}](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-apis/lead-api.md).\n\nError response: List of errors detected when trying to process the request. These error messages are defined in the LeadAPIConstants script include.\n\nData type: Object\n\n</td></tr><tr><td>\n\n&lt;JSONobject&gt;.status\n\n</td><td>\n\nResponse status code.These status codes are defined in the LeadAPIConstants script include.\n\nData type: String\n\n</td></tr></tbody>\n</table>The following code example shows where to add your custom code for the processUpdateLead\\(\\) method in the LeadAPIProcessUtil script include.\n\n```\nvar LeadAPIProcessUtil = Class.create();\n\nLeadAPIProcessUtil.prototype = Object.extendsObject(LeadAPIProcessUtilOOB, {\n\n// Define overriding functions here \n\nprocessUpdateLead: function(requestBody, id) { \n// Add your custom code here\n},\n\ntype: 'LeadAPIProcessUtil' \n\n}); \n```\n\n"}}