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


---

# Client - Scoped, Global

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

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

The Client API provides methods to add data to the MetricBase database, to execute transforms on the MetricBase
database, and to receive the results of the transforms.

You can use the Client class in both scoped and global server scripts.
This class is part of the MetricBase application and must run within the
`sn_clotho` namespace.

## Client - Client() {#ariaid-title2}

Create an instance of the client class to access the MetricBase database.
{#ClientS-Client__table_pzg_hvz_31b__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#ClientS-Client__table_pzg_hvz_31b}  

    var client = new sn_clotho.Client();

## Client - accumulate(GlideRecord now_GR, String metric) {#ariaid-title3}

Accumulates metric values at specified timestamp and saves the result to the database rather than overwriting the value.
Use this method to handle metrics that can be summed for an accumulation, such as kilowatt-hours (kWhs) of electricity. Accumulate makes a call for each metric at the provided timestamp. For example, collected kilowatts for a heater, electric kettle, and washing machine would result in three calls to accumulate.
{#ClientS-accumulate_GR_N__table_zsz_5jd_1db__entry__3}

| Name | Type | Description |
|-|-|-|
| now_GR | GlideRecord | Name of the series GlideRecord from which to obtain the accumulated value. See also: [getSeries()](https://servicenow-prod.fluidtopics.net/tWthf27ZYLZyhFfPsj4Jiw#ClientS-getSeries_O_S_O "Get all series from a specific dimension.") |
| default_value | Number | Optional. Default value for accumulation at a given timestamp. Used only during the first call to accumulate if a value is unavailable for a given timestamp. A use case could be accumulating a watts metric for a total_power. You want to accumulate watts for a router connected to an outlet without a power meter to measure it. If you know the consumption value and it is constant), you can use the constant value as a default value to accumulate total_power. For example, you would use 20 if the router is constantly plugged in and consumes 20 Watts. The timestamp value can be provided using the [DataBuilder](https://servicenow-prod.fluidtopics.net/w31iV5_nztziv_p~DGoG8A#DataBuilderScopedAPI "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.") API. Default: 0 |
[Table 2. Parameters]

{#ClientS-accumulate_GR_N__table_zsz_5jd_1db} {#ClientS-accumulate_GR_N__table_atz_5jd_1db__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 3. Returns]

{#ClientS-accumulate_GR_N__table_atz_5jd_1db}  
The following example shows how to accumulate the `total_power` metric value
in a record called `building_a`.

    var time = new GlideDateTime();

    // total_power is the name of a metric within building_a which stores accumulated values

    var dataBuilder1 = new sn_clotho.DataBuilder(building_a, "total_power");
    // values to be accumulated
    dataBuilder1.add(time, 3.5);
    new sn_clotho.Client().accumulate(dataBuilder1, 0);

    var dataBuilder2 = new sn_clotho.DataBuilder(building_a, "total_power");
    // values to be accumulated
    dataBuilder2.add(time, 3.5);
    new sn_clotho.Client().accumulate(dataBuilder2, 0);

    var dataBuilder3 = new sn_clotho.DataBuilder(building_a, "total_power");
    // values to be accumulated
    dataBuilder3.add(time, 3.5);
    new sn_clotho.Client().accumulate(dataBuilder3, 0);

    // As a result of these operations client will save value of
    // 3.5+12+4.3+0(default value) at the timestamp 'time'

## Client - deleteMetric(String tableName, String metricName) {#ariaid-title4}

Remove a specified metric from a specified table in the MetricBase
database
Note:  
This method deletes data from the MetricBase database. There is no recovery mechanism.
{#ClientS-deleteMetric_S_S__table_zsz_5jd_1db__entry__3}

| Name | Type | Description |
|-|-|-|
| tableName | String | The name of the table whose specified metric is to be deleted. |
| metricName | String | The name of the metric. |
[Table 4. Parameters]

{#ClientS-deleteMetric_S_S__table_zsz_5jd_1db} {#ClientS-deleteMetric_S_S__table_atz_5jd_1db__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 5. Returns]

{#ClientS-deleteMetric_S_S__table_atz_5jd_1db}  
The following example shows how to remove a metric from a table.

    var client = new sn_clotho.Client();

    // delete metric (Speed) from the Drones table
    client.deleteMetric("mb_demo_drone", "mb_demo_mt_speed");

## Client - deleteSeries(GlideRecord now_GR, String metric) {#ariaid-title5}

Remove the data in the MetricBase database associated with
the specified metric in the specified GlideRecord. Use this method for removing test data.
Note:  
This method deletes data from the MetricBase database. There is no recovery mechanism.
{#ClientS-deleteSeries_GR_S__table_zsz_5jd_1db__entry__3}

| Name | Type | Description |
|-|-|-|
| now_GR | GlideRecord | The records whose time series data for the specified metric is to be deleted. |
| metric | String | The name of the metric. |
[Table 6. Parameters]

{#ClientS-deleteSeries_GR_S__table_zsz_5jd_1db} {#ClientS-deleteSeries_GR_S__table_atz_5jd_1db__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 7. Returns]

{#ClientS-deleteSeries_GR_S__table_atz_5jd_1db}  

    var client = new sn_clotho.Client();
    //query drones of a specific model
    var drones = new GlideRecord("mb_demo_drone");
    drones.addQuery("model", "Kingfisher Phantom");
    drones.query();

    client.deleteSeries(drones, 'mb_demo_mt_speed');

## Client - getSeries(GlideRecord now_GR, String metricName, GlideDateTime
lastUpdateBefore) {#ariaid-title6}

Get all series from a specific dimension.
{#ClientS-getSeries_O_S_O__table_zsz_5jd_1db__entry__3}

| Name | Type | Description |
|-|-|-|
| now_GR | [GlideRecord](https://servicenow-prod.fluidtopics.net/Z64TK~kWnpWTEG5bCPvZuQ#c_GlideRecordScopedAPI "The scoped GlideRecord API is used for database operations.") | The record from which to obtain the series. |
| metric | String | The name of the metric. |
| lastUpdateBefore | [GlideDateTime](https://servicenow-prod.fluidtopics.net/xOhnNqU1cKMjoQSfmtxVCw#c_GlideDateTimeScoped "The scoped GlideDateTime class provides methods for performing operations on GlideDateTime objects.") | Optional. Date in the future representing the end of the period to be evaluated. |
[Table 8. Parameters]

{#ClientS-getSeries_O_S_O__table_zsz_5jd_1db} {#ClientS-getSeries_O_S_O__table_atz_5jd_1db__entry__2}

| Type | Description |
|-|-|
| Array | List of string sys_ids representing the series containing data for the specified metric. If the lastUpdateBefore parameter is provided, returns series that have no data more recent than the lastUpdateBefore date (non-inclusive). |
[Table 9. Returns]

{#ClientS-getSeries_O_S_O__table_atz_5jd_1db}  
The following example shows how to get the complete list of speed values listed in the
Drones \[mb_demo_drone\] table.

    var client = new sn_clotho.Client();

    // query subject records
    var grDrone = new GlideRecord('mb_demo_drone');
    grDrone.query();

    var series = client.getSeries(grDrone,'mb_demo_mt_speed');

## Client - put(Object metricData) {#ariaid-title7}

Saves metric data to the MetricBase database.
{#ClientS-put_DB__table_vxt_wvz_31b__entry__3}

| Name | Type | Description |
|-|-|-|
| metricData | Object | One of the following: * [DataBuilder](https://servicenow-prod.fluidtopics.net/w31iV5_nztziv_p~DGoG8A#DataBuilderScopedAPI "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.") object containing metric data. * Array of DataBuilder objects containing metric data. {#ClientS-put_DB__ul_ldw_bbh_yjb} |
[Table 10. Parameters]

{#ClientS-put_DB__table_vxt_wvz_31b} {#ClientS-put_DB__table_wxt_wvz_31b__entry__2}

| Type | Description |
|-|-|
| void |   |
[Table 11. Returns]

{#ClientS-put_DB__table_wxt_wvz_31b}  

    var time = new GlideDateTime();
    ​
    // two different GlideRecord instances and metrics
    var dataBuilder = new sn_clotho.DataBuilder(now_GR, 'cpu_percentage');
    dataBuilder.add(time, 0.6);
    ​
    var dataBuilder2 = new sn_clotho.DataBuilder(gr2, 'disk_free_percentage');
    dataBuilder2.add(time, 0.2);
    ​
    new sn_clotho.Client().put([dataBuilder,dataBuilder2]);


