{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":724,"path":"api-reference/server-api-reference/CheckDefinitionTestBuilderAPIScope.md","title":"CheckDefinitionTestBuilder - Scoped","bundle":null,"doc_type":null,"release":"australia","body":"\n# CheckDefinitionTestBuilder- Scoped\n\nThe CheckDefinitionTestBuilder script include provides methods that enable you to building test check requests on check definitions.\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 definition 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## CheckDefinitionTestBuilder - CheckDefinitionTestBuilder\\(\\)\n\nCreates an CheckDefinitionTestBuilder instance.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\nThe following example shows how to initialize CheckDefinitionTestBuilder.\n\n```\nvar builder = new sn_agent.CheckDefinitionTestBuilder();\n```\n\n## CheckDefinitionTestBuilder - 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.CheckDefinitionTestBuilder();\n\nvar testResultJson = builder.withCheckId(checkId).withCiId(ciId).build();\n\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n## CheckDefinitionTestBuilder - 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|CheckDefinitionTestBuilder|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.CheckDefinitionTestBuilder();\nvar testResultJson = builder.withCheckId(checkId).withCiId(ciId).build();\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n## CheckDefinitionTestBuilder - 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|CheckDefinitionTestBuilder|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.CheckDefinitionTestBuilder();\nvar testResultJson = builder.withCheckId(checkId).withCiId(ciId).build();\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n## CheckDefinitionTestBuilder - 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 record.|\n\n|Type|Description|\n|----|-----------|\n|CheckDefinitionTestBuilder|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.CheckDefinitionTestBuilder();\nvar testResultJson = builder.withCheckId(checkId).withCredentialsAliasId(credAlias).build();\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n## CheckDefinitionTestBuilder - 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|CheckDefinitionTestBuilder|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.CheckDefinitionTestBuilder();\nvar testResultJson = builder.withCheckId(checkId).withCredentialsAliasName(credentialsAliasName).build();\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n## CheckDefinitionTestBuilder - 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|CheckDefinitionTestBuilder|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.CheckDefinitionTestBuilder();\nvar testResultJson = builder.withCheckId(checkId).withCredentialsId(credID).build();\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n## CheckDefinitionTestBuilder - 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|CheckDefinitionTestBuilder|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.CheckDefinitionTestBuilder();\nvar testResultJson = builder.withCheckId(checkId).withCredentialsName(credName).build();\nif (!gs.nil(testResultJson.error))\n\tgs.error(testResultJson.error);\n```\n\n"}}