{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":707,"path":"api-reference/server-api-reference/AgentNowHandlerAPIScoped.md","title":"AgentNowHandler - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# AgentNowHandler- Scoped\n\nThe AgentNowHandler script include provides methods that enable running check definitions on demand, checking the status of on demand executions and test check executions and for stopping background checks that were executed on demand.\n\nThis script include requires the Agent Client Collector Framework \\(sn\\_agent\\) store application and is provided within the `sn_agent` namespace. For more information, refer to [Agent Client Collector](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/it-operations-management/acc-landing-page.md).\n\nFor the REST API solution, refer to [Agent Client Collector API](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/rest-apis/agnt_clnt_cll-api.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## AgentNowHandler - AgentNowHandler\\(\\)\n\nCreates an AgentNowHandler instance.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\nThe following example shows how to initialize AgentNowHandler.\n\n```\nvar handler = new sn_agent.AgentNowHandler();\n```\n\n## AgentNowHandler - getRequestStatus\\(String requestId\\)\n\nGets status of the request with the given ID.\n\n|Name|Type|Description|\n|----|----|-----------|\n|requestId|String|A check request ID generated by calling the runCheckForCis\\(\\) method.|\n\n<table id=\"table_al2_2g2_z4b\" class=\"returns\"><thead><tr><th>\n\nProperties\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nObject\n\n</td><td>\n\nStatus of the request and any applicable error message.\n\n</td></tr><tr><td>\n\nstatus\n\n</td><td>\n\nRequest status.Possible values:\n\n-   done – Check is successful.\n-   failure – Check has failed. See error message for details.\n-   mid\\_flow – Request output is being handled by the MID server.\n-   processing – Check is in progress.\n-   timeout – Check processing exceeded time limit set in the runCheckForCis\\(\\) method.\n\n Data type: String\n\n</td></tr><tr><td>\n\nerr\\_msg\n\n</td><td>\n\nError message if any.Possible values:\n\n-   No agents found for relevant CIs.\n-   No background check request with given ID.\n-   No request with given ID.\n-   No test result with given ID.\n-   Request timeout.\n\n Data type: String\n\n</td></tr></tbody>\n</table>The following example shows how to get the status of a request.\n\n```\nvar handler = new sn_agent.AgentNowHandler();\nvar check = {checkDefId: \"158279505372b30034b8ddeeff7b1270\"};\nvar computerGr = new GlideRecord(\"cmdb_ci_computer\");\ncomputerGr.query();\nvar requestId = handler.runCheckForCis(computerGr, check, 0, 60);\n\nvar reqStatusJson = handler.getRequestStatus(requestId);\ngs.info(JSON.stringify(reqStatusJson));\n```\n\n## AgentNowHandler - getTestResultStatus\\(String testResultId\\)\n\nGets the test check status of the given test result.\n\n|Name|Type|Description|\n|----|----|-----------|\n|testResultId|String|A test result ID generated by creating a test check request.|\n\n<table id=\"table_al2_2g2_z4b\" class=\"returns\"><thead><tr><th>\n\nProperties\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nstatus\n\n</td><td>\n\nStatus of the test results.Possible values:\n\n-   0: Pending\n-   1: In progress\n-   2: Complete\n-   3: No test result with given ID\n\n Data type: String\n\n</td></tr><tr><td>\n\noutput\n\n</td><td>\n\nOutput describing the status.Data type: String\n\n</td></tr></tbody>\n</table>The following example shows how get result status of a completed test check request.\n\n```\nvar testCheckStatusJson = handler.getTestResultStatus(\"testResultId\");\ngs.info(JSON.stringify(testCheckStatusJson));\n```\n\n## AgentNowHandler - runCheckForCis\\(Object cis, Object check, Number priority, Number timeout\\)\n\nRuns a check against the given configuration item.\n\n<table id=\"table_zk2_2g2_z4b\" 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\ncis\n\n</td><td>\n\n[GlideRecord](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n\n</td><td>\n\nGlideRecord of any CMDB table \\(any application, host, or agent\\) that the check is working against.\n\n</td></tr><tr><td>\n\ncheck\n\n</td><td>\n\nObject\n\n</td><td>\n\nCheck ID and optional check parameters. ```\n\"check\": {\n  \"checkDefId\": \"String\",\n  \"params\": {Object}\n}\n```\n\n</td></tr><tr><td>\n\ncheck.checkDefId\n\n</td><td>\n\nString\n\n</td><td>\n\nSys\\_id of a check definition in the Check Definitions \\[sn\\_agent\\_check\\_def\\] table.\n\n</td></tr><tr><td>\n\ncheck.params\n\n</td><td>\n\nObject\n\n</td><td>\n\nOptional. Map of parameter names and values. These settings can be used to override the parameter records of the check definition and its specified values. ```\n\"params\": {\n  \"<parameter name>\": \"String\"\n}\n```\n\n</td></tr><tr><td>\n\npriority\n\n</td><td>\n\nNumber\n\n</td><td>\n\nPriority of the request to be set on the ECC queue. Possible values:\n\n-   0: interactive\n-   1: expedited\n-   2: standard\n\n</td></tr><tr><td>\n\ntimeout\n\n</td><td>\n\nNumber\n\n</td><td>\n\nValue of the timeout for the request in seconds.\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|String|Sys\\_id of the generated background check request.|\n\nThe following example shows how to run a background check and get its request ID.\n\n```\nvar handler = new sn_agent.AgentNowHandler();\nvar check = {checkDefId: \"028fcd5067c80010b7b72dbd2685ef4f\"};\nvar computerGr = new GlideRecord(\"cmdb_ci_computer\");\ncomputerGr.query();\nvar requestId = handler.runCheckForCis(computerGr, check, 0, 60);\n\ngs.info(requestId);\n```\n\nOutput:\n\n```\nb9cf14aedb5e30106f4810284b961990\n```\n\n## AgentNowHandler - stopBackgroundCheck\\(String requestId\\)\n\nStops a background check.\n\nTo start a background check, use the runCheckForCis\\(\\) method.\n\n|Name|Type|Description|\n|----|----|-----------|\n|requestId|String|The ID of a background check request generated by calling the runCheckForCis\\(\\) method.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following example shows how stop executing a background check.\n\n```\nhandler.stopBackgroundCheck(backRequestId);\n\n```\n\n"}}