Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Having issue with trendby in spline data visualization component

RahulJ2
Tera Contributor

Hi All,

I am new to ui builder, I have added data visualization component and set type is Spline. As I want to pass dynamic filter based on date added in filter

Data sources -

 

 

function evaluateProperty({api, helpers}) {
 var data =  [ {
                   "isDatabaseView": false,
                   "allowRealTime": true,
                   "sourceType": "table",
                   "label": {
                       "message": "LABEL OF YOUR DV"
                   },
                   "tableOrViewName": "task", // tablename
                   "filterQuery": "opened_atBETWEENjavascript:gs.dateGenerate('"+api.state.startDate+"','00:00:00')@javascript:gs.dateGenerate('"+api.state.endDate+"','23:59:59')",//based on filter bind value
                   "id": "SPLINEDVID"
               }];
           console.log("data = "+JSON.stringify(data));
   return data;
}

 

 

 

Metric script :

 

 

 

/**
  *  {params} params
  *  {api} params.api
  *  {TransformApiHelpers} params.helpers
  */
function evaluateProperty({
   api,
   helpers
}) {
   var metric = [{
                   "dataSource": "SPLINEDVID",
                   "id": "METRICID",
                   "aggregateFunction": "COUNT",
                   "aggregateField":"",
                   "numberFormat": {
                       "customFormat": false
                   },
                   "axisId": "primary"
               }];
   return metric;
}

 

 

Trend by script :

 

 

/**
  *  {params} params
  *  {api} params.api
  *  {TransformApiHelpers} params.helpers
  */
function evaluateProperty({
   api,
   helpers
}) {
   var metric = [{
                   "dataSource": "SPLINEDVID",
                   "id": "METRICID",
                   "aggregateFunction": "COUNT",
                   "aggregateField":"",
                   "numberFormat": {
                       "customFormat": false
                   },
                   "axisId": "primary"
               }];
   return metric;
}

 

 

 

It was showing below error in dashboard

RahulJ2_0-1713757606458.png

 

Anyone have any idea what i am missing here in trendby script

 

 

 

 

2 REPLIES 2

Dibyaratnam
Tera Sage

why is your metric and trendby script same?

RahulJ2
Tera Contributor

no both are different

Data source -

function evaluateProperty({api, helpers}) {
 return[{
                   "isDatabaseView": false,
                   "allowRealTime": true,
                   "sourceType": "table",
                   "label": {
                       "message": "LABEL OF YOUR DV"
                   },
                   "tableOrViewName": "task", // tablename
                  // "filterQuery": "opened_atBETWEENjavascript:gs.dateGenerate('"+api.state.startDate+"','00:00:00')@javascript:gs.dateGenerate('"+api.state.endDate+"','23:59:59')",//based on filter bind value
                 "filterQuery":"opened_atBETWEENjavascript:gs.dateGenerate('2023-07-01','00:00:00')@javascript:gs.dateGenerate('2024-04-22','23:59:59')",
                   "id": "SPLINEDVID"
               }];
}

Metric script

/**
  * @Param {params} params
  * @Param {api} params.api
  * @Param {TransformApiHelpers} params.helpers
  */
function evaluateProperty({
   api,
   helpers
}) {
   return [{
                   "dataSource": "SPLINEDVID",
                   "id": "METRICID1",
                   "aggregateFunction": "COUNT",
                   "aggregateField":"",
                   "numberFormat": {
                       "customFormat": false
                   },
                   "axisId": "primary"
               }];

}

Trend by

/**
  * @Param {params} params
  * @Param {api} params.api
  * @Param {TransformApiHelpers} params.helpers
  */
function evaluateProperty({api, helpers}) {
 return {
        "trendByFrequency": "date",
        "trendByFields": [{
            "field": "sys_updated_on",
            "metric": "METRICID1"

        }]
    };
}