---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# DataBuilder - Scoped, Global

# DataBuilder - Scoped, Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 minutes to read

The 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.

You can call this class in scoped and global server scripts. When using the DataBuilder class, use the `sn_clotho` namespace identifier.

This class is part of the MetricBase application.

## DataBuilder - DataBuilder(Object glideRecord, String subject, String metric) {#ariaid-title2}

Creates an instance of the DataBuilder class.
{#SDB-DataBuilder_S_S_S__table_yjn_kgf_31b__entry__3}

| Name | Type | Description |
|-|-|-|
| glideRecord | Object | GlideRecord from which to obtain the domain. |
| subject | String | The sys_id of the GlideRecord associated with this series. |
| metric | String | The field name of the metric. |
[Table 1. Parameters]

{#SDB-DataBuilder_S_S_S__table_yjn_kgf_31b}  
The 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.

    // Where cpu_percentage is the name of the metric
            var dataBuilder = new sn_clotho.DataBuilder(now_GR, 'cpu_percentage');

## DataBuilder - add(GlideDateTime start, Array value) {#ariaid-title3}

Adds a series of data points to the DataBuilder object. Each data point is a time stamp and a value.
Uses 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.
{#SDB-add_GDT_A__table_xy1_c1m_31b__entry__3}

| Name | Type | Description |
|-|-|-|
| start | GlideDateTime | The time stamp for the first data point. Subsequent time stamps are calculated using the retention policy collection period. |
| value | Array | An array of numbers. |
[Table 2. Parameters]

{#SDB-add_GDT_A__table_xy1_c1m_31b} {#SDB-add_GDT_A__table_yy1_c1m_31b__entry__2}

| Type | Description |
|-|-|
| DataBuilder | The same DataBuilder object. |
[Table 3. Returns]

{#SDB-add_GDT_A__table_yy1_c1m_31b}  
The 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.

A 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.


    var points = [7,0.5,273];
    var dataBuilder = new sn_clotho.DataBuilder(now_GR, 'cpu_percentage');
    // this creates a GlideDateTime object set to the current date and time
    var time = new GlideDateTime();
    dataBuilder.add(time, points);

## DataBuilder - add(GlideDateTime start, Number value) {#ariaid-title4}

Adds 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.
{#SDB-add_GDT_N__table_r1w_2vl_31b__entry__3}

| Name | Type | Description |
|-|-|-|
| start | GlideDateTime | The time stamp for the data point. |
| value | Number | The value of the data point. |
[Table 4. Parameters]

{#SDB-add_GDT_N__table_r1w_2vl_31b} {#SDB-add_GDT_N__table_s1w_2vl_31b__entry__2}

| Type | Description |
|-|-|
| DataBuilder | The DataBuilder object. |
[Table 5. Returns]

{#SDB-add_GDT_N__table_s1w_2vl_31b}  
The 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.

    var dataBuilder = new sn_clotho.DataBuilder(now_GR, 'cpu_percentage');
    // this creates a GlideDateTime object set to the current date and time
    var time = new GlideDateTime();
    dataBuilder.add(time, 0.6);


