Transformer - Scoped, Global

  • Rversion finale: Australia
  • Mis à jour 12 mars 2026
  • 2 minutes de lecture
  • The Transformer API manipulates time-series data to prepare the data for evaluation and analysis.

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

    The general use case is to determine the period to be evaluated, select the records from the table with the metric field, define the type of transform to run, and then execute the transform.
    // create the start and end time
           var start = new GlideDateTime();
    	start.addSeconds(-1 * 60 * 60); 
    	var end = new GlideDateTime();
    	
    	//mb_demo_drone is a table with metric fields. 
    	var drones = new GlideRecord("mb_demo_drone");
    	drones.addQuery("model", "Kingfisher Phantom");
    	drones.query();
    
    	//build a transform that returns a simple average
    	var builder = new sn_clotho.Transformer(drones);
    	builder.metric("mb_demo_mt_rem_battery").avg().label("Original");
    
    	//execute transform and return result for visualization
    	var result = builder.execute(start,end);

    This class is part of the MetricBase application.

    Transformer - Transformer( GlideRecord sourceRecords)

    Create a Transformer object.

    Tableau 1. Parameters
    Name Type Description
    sourceRecords GlideRecord Contains the records for which metrics are to be evaluated. Can be one record or many.
    //where drones is a GlideRecord created from a table with a metric field
    	var builder = new sn_clotho.Transformer(drones);
    

    Transformer - execute(GlideDateTime start, GlideDateTime end)

    Run the transform.

    Use the metric() and groupBy() methods before calling execute(). The execute() method can only be called once for each Transformer object.

    Actions performed as part of the transform do not change the data in the MetricBase database.

    Tableau 2. Parameters
    Name Type Description
    start GlideDateTime The beginning of the period to be evaluated.
    end GlideDateTime The end of the period to be evaluated.
    Tableau 3. Returns
    Type Description
    TransformResult The transformed data.
    var minutesAgoStart = 60;
    	var end = new GlideDateTime();
    	var start = new GlideDateTime(end);
    	start.addSeconds(-1 * 60 * minutesAgoStart);
    	
    	// query subject records
    	var grDrone = new GlideRecord('mb_demo_drone');
    	grDrone.query();
    	
    	// building transform; get the average transforms of a metric, grouping by model
    	var transformer = new sn_clotho.Transformer(grDrone);
    	transformer.groupBy("fleet").metric("mb_demo_mt_altitude").avg().label('avg - %g:fleet:');
    
    	// execute and return result for visualization
    	var tfrmResult = transformer.execute(start, end);

    Transformer - groupBy(String field)

    Specifies the field to use to group the data.

    If you are going to use the groupBy() method, you must call it must before calling the execute() method.

    Tableau 4. Parameters
    Name Type Description
    field String The field in the table to use to group the transform results.
    Tableau 5. Returns
    Type Description
    TransformPart A TransformPart object that you can use to specify the transform characteristics.
    var transformer = new sn_clotho.Transformer(grDrone);
    var trnsfrm = transformer.groupBy("fleet");

    Transformer - metric(String metricName)

    Specify the metric field to be used in the transform.

    You can specify multiple metrics to be used in the transform. The metric() method cannot be called after the execute() method is called.

    Tableau 6. Parameters
    Name Type Description
    metricName String Name of the metric field.
    Tableau 7. Returns
    Type Description
    TransformPart A TransformPart object that can be used to specify the transform characteristics.
    var transformer = new sn_clotho.Transformer(grDrone);
    var trnsfrm = transformer.metric("mb_demo_mt_altitude");