{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":741,"path":"api-reference/server-api-reference/DataBuilderScopedAPI.md","title":"DataBuilder - Scoped, Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# DataBuilder - Scoped, Global\n\nThe DataBuilder API provides methods to create a series of data points for a metric. Use the sn\\_clotho.Client.put\\(\\) method to save the values.\n\nYou can call this class in scoped and global server scripts. When using the DataBuilder class, use the `sn_clotho` namespace identifier.\n\nThis class is part of the MetricBase application.\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## DataBuilder - DataBuilder\\(Object glideRecord, String subject, String metric\\)\n\nCreates an instance of the DataBuilder class.\n\n|Name|Type|Description|\n|----|----|-----------|\n|glideRecord|Object|GlideRecord from which to obtain the domain.|\n|subject|String|The sys\\_id of the GlideRecord associated with this series.|\n|metric|String|The field name of the metric.|\n\nThe following example initializes a new instance of `DataBuilder` from the `sn_clotho` namespace using the `now_GR` parameter, which represents the current time or a specific time range, and the string parameter `'cpu_percentage'`, which is the name of the metric being tracked.\n\n```\n// Where cpu_percentage is the name of the metric\n        var dataBuilder = new sn_clotho.DataBuilder(now_GR, 'cpu_percentage');\n```\n\n## DataBuilder - add\\(GlideDateTime start, Array value\\)\n\nAdds a series of data points to the DataBuilder object. Each data point is a time stamp and a value.\n\nUses the start parameter and the retention policy collection period to calculate the time stamp for each value in the array. The first value has the start parameter as the time stamp. This method does not save the data in the MetricBase database. Use the sn\\_clotho.Client.put\\(\\) method to save the values.\n\n|Name|Type|Description|\n|----|----|-----------|\n|start|GlideDateTime|The time stamp for the first data point. Subsequent time stamps are calculated using the retention policy collection period.|\n|value|Array|An array of numbers.|\n\n|Type|Description|\n|----|-----------|\n|DataBuilder|The same DataBuilder object.|\n\nThe following example first initializes an array \\(points\\) containing three numerical values: 7, 0.5, and 273, which represent different data points related to CPU usage at a given timestamp. Then, the code initializes a new `sn_clotho.DataBuilder` object using `now_GR` \\(a GlideRecord object\\) represents the target database record where this data is being stored. `'cpu_percentage'` is the metric name used to track CPU usage.\n\nA new time variable is created using GlideDateTime, which sets the object to the current date and time. Finally, the code uses `dataBuilder.add(time, points)` to store multiple data points in the Data Builder object.\n\n```\n\nvar points = [7,0.5,273];\nvar dataBuilder = new sn_clotho.DataBuilder(now_GR, 'cpu_percentage');\n// this creates a GlideDateTime object set to the current date and time\nvar time = new GlideDateTime();\ndataBuilder.add(time, points);\n```\n\n## DataBuilder - add\\(GlideDateTime start, Number value\\)\n\nAdds a data point to the DataBuilder object. Each data point is a time stamp and a value. This method does not save the data point in the metric. Use the sn\\_clotho.Client.put\\(\\) method to save the values.\n\n|Name|Type|Description|\n|----|----|-----------|\n|start|GlideDateTime|The time stamp for the data point.|\n|value|Number|The value of the data point.|\n\n|Type|Description|\n|----|-----------|\n|DataBuilder|The DataBuilder object.|\n\nThe following example first initializes a new instance of `DataBuilder` from the `sn_clotho` namespace using the parameters `now_GR` \\(the target record\\) and `'cpu_percentage'` \\(the metric to track\\). `GlideDateTime` initializes time to the current date and time. Finally, `dataBuilder.add()` stores the value `0.6` \\(representing a value of 60% CPU usage\\) at the current timestamp.\n\n```\nvar dataBuilder = new sn_clotho.DataBuilder(now_GR, 'cpu_percentage');\n// this creates a GlideDateTime object set to the current date and time\nvar time = new GlideDateTime();\ndataBuilder.add(time, 0.6);\n```\n\n"}}