{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":725,"path":"api-reference/server-api-reference/CheckInstanceTestBuilderAPIScoped.md","title":"CheckInstanceTestBuilder - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# CheckInstanceTestBuilder- Scoped\n\nThe CheckInstanceTestBuilder script include provides methods that enable building test check requests on check instances.\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\nThis script include provides methods that enable the following:\n\n-   Set the check instance to test\n-   Set the configuration item to run the test against\n\nYou can also specify one of the following identifiers to use during the test:\n\n-   Credential sys\\_id\n-   Credential alias id\n-   Credential name\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## CheckInstanceTestBuilder - CheckInstanceTestBuilder\\(\\)\n\nCreates an CheckInstanceTestBuilder instance.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\nThe following example shows how to initialize CheckInstanceTestBuilder.\n\n```\nvar builder = new sn_agent.CheckInstanceTestBuilder();\n```\n\n## CheckInstanceTestBuilder - build\\(\\)\n\nBuilds the test check request with the arguments set.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Properties|Description|\n|----------|-----------|\n|Object|JSON object with two attributes – the test result record ID and an error. If the build is successful, the test result ID returns and error is null. If an error occurs during the build, the test result ID is null and the error displays.|\n\nThe following example shows how build a test check request:\n\n```\nvar checkId = \"158279505372b30034b8ddeeff7b1270\";\nvar ciId = \"cc0dcc855374301062d1ddeeff7b12b0\";\nvar builder = new sn_agent.CheckInstanceTestBuilder();\n\nvar testResultJson = builder.withCheckId(checkId).withCiId(ciId).build();\n\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n## CheckInstanceTestBuilder - withCheckId\\(String checkId\\)\n\nSets the sys\\_id of the check definition to test.\n\n|Name|Type|Description|\n|----|----|-----------|\n|checkId|String|Sys\\_id of the check definition listed in the Check Definitions \\[sn\\_agent\\_check\\_def\\] table.|\n\n|Type|Description|\n|----|-----------|\n|CheckInstanceTestBuilder|The builder instance the method was invoked for.|\n\nThe following example shows how create a test check.\n\n```\nvar checkId = \"158279505372b30034b8ddeeff7b1270\";\nvar ciId = \"cc0dcc855374301062d1ddeeff7b12b0\";\nvar builder = new sn_agent.CheckInstanceTestBuilder();\nvar testResultJson = builder.withCheckId(checkId).withCiId(ciId).build();\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n## CheckInstanceTestBuilder - withCiId\\(String ciId\\)\n\nSets the sys\\_id of the configuration item to run the test against.\n\n|Name|Type|Description|\n|----|----|-----------|\n|ciId|String|Sys\\_id of a CMDB Configuration Item.|\n\n|Type|Description|\n|----|-----------|\n|CheckInstanceTestBuilder|The builder instance the method was invoked for.|\n\nThe following example shows how to create a test check request with\n\n```\nvar checkId = \"158279505372b30034b8ddeeff7b1270\";\nvar ciId = \"cc0dcc855374301062d1ddeeff7b12b0\";\nvar builder = new sn_agent.CheckInstanceTestBuilder();\nvar testResultJson = builder.withCheckId(checkId).withCiId(ciId).build();\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n## CheckInstanceTestBuilder - withCredentialsAliasId\\(String credentialsAliasId\\)\n\nSets the credentials alias sys\\_id to use during the test.\n\n**Note:** Running this removes any previous assignment done by calling withCredentialsName, withCredentialsAliasId or withCredentialsAliasName.\n\n|Name|Type|Description|\n|----|----|-----------|\n|credentialsAliasId|String|Sys\\_id of a credentials alias record.|\n\n|Type|Description|\n|----|-----------|\n|CheckInstanceTestBuilder|The builder instance the method was invoked for.|\n\nThe following example shows how create a test check and set the credentials alias ID.\n\n```\nvar checkId = \"158279505372b30034b8ddeeff7b1270\";\nvar credAlias = \"<sys_id>\";\nvar builder = new sn_agent.CheckInstanceTestBuilder();\nvar testResultJson = builder.withCheckId(checkId).withCredentialsAliasId(credAlias).build();\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n## CheckInstanceTestBuilder - withCredentialsAliasName\\(String credentialsAliasName\\)\n\nSets the credentials alias name to use during the test. If the given value matches the name of multiple credentials aliases records, then one of them is chosen randomly.\n\n**Note:** Running this removes any previous assignment done by calling withCredentialsName, withCredentialsAliasId or withCredentialsAliasName.\n\n|Name|Type|Description|\n|----|----|-----------|\n|credentialsAliasName|String|Name of a credentials alias.|\n\n|Type|Description|\n|----|-----------|\n|CheckInstanceTestBuilder|The builder instance the method was invoked for.|\n\nThe following example shows how create a test check and set the credentials alias name.\n\n```\nvar checkId = \"158279505372b30034b8ddeeff7b1270\";\nvar credentialsAliasName = \"credentialsAliasName\";\nvar builder = new sn_agent.CheckInstanceTestBuilder();\nvar testResultJson = builder.withCheckId(checkId).withCredentialsAliasName(credentialsAliasName).build();\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n## CheckInstanceTestBuilder - withCredentialsId\\(String credentialsId\\)\n\nSets the credentials sys\\_id to use during the test.\n\n**Note:** Running this removes any previous assignment done by calling withCredentialsName, withCredentialsAliasId or withCredentialsAliasName.\n\n|Name|Type|Description|\n|----|----|-----------|\n|credentialsId|String|Sys\\_id of a credentials record.|\n\n|Type|Description|\n|----|-----------|\n|CheckInstanceTestBuilder|The builder instance the method was invoked for.|\n\nThe following example shows how create a test check and set the credentials ID.\n\n```\nvar checkId = \"158279505372b30034b8ddeeff7b1270\";\nvar credID = \"<sys_id>\";\nvar builder = new sn_agent.CheckInstanceTestBuilder();\nvar testResultJson = builder.withCheckId(checkId).withCredentialsId(credID).build();\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n## CheckInstanceTestBuilder - withCredentialsName\\(String credentialsName\\)\n\nSets the credentials name to use during the test. If the given value is the name of several credentials records, then one of them is chosen randomly.\n\n**Note:** Running this removes any previous assignment done by calling withCredentialsName, withCredentialsAliasId or withCredentialsAliasName.\n\n|Name|Type|Description|\n|----|----|-----------|\n|credentialsName|String|Name of the credentials record.|\n\n|Type|Description|\n|----|-----------|\n|CheckInstanceTestBuilder|The builder instance the method was invoked for.|\n\nThe following example shows how create a test check and set the credentials name.\n\n```\nvar checkId = \"158279505372b30034b8ddeeff7b1270\";\nvar credname = \"credentialsName\";\nvar builder = new sn_agent.CheckInstanceTestBuilder();\nvar testResultJson = builder.withCheckId(checkId).withCredentialsName(credName).build();\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n## CheckInstanceTestBuilder - withProxyAgentId\\(String agentId\\)\n\nSets the agent to run the test. Allowed only in case the tested check instance and policy are proxy.\n\n|Name|Type|Description|\n|----|----|-----------|\n|agentId|String|Unique ID of an agent proxy to run this check. This value is listed in the Agent ID column of the Agent Client Collectors \\[sn\\_agent\\_cmdb\\_ci\\_agent\\] table.|\n\n|Type|Description|\n|----|-----------|\n|CheckInstanceTestBuilder|The builder instance the method was invoked for.|\n\nThe following example shows how create a test check and set the proxy agent ID.\n\n```\nvar checkId = \"158279505372b30034b8ddeeff7b1270\";\nvar agentId = \"<agentID>\";\nvar builder = new sn_agent.CheckInstanceTestBuilder();\nvar testResultJson = builder.withCheckId(checkId).withAgentId(agentId).build();\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n"}}