UI Builder Single Score make filter with bind data

Nadia7
Tera Expert

Hi Community

 

Please advise how I can make condition with bind data for data source for single score.

There isn't such options there.

I need to get locations from @Data.look_up_user_preferences_1.result.location

Thank you

 

 

 

 

1 ACCEPTED SOLUTION

@Nadia7,

In the metric use this code:

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

Aggregate field is not required as its a single score and not charts are used.

 

 

Let me know if it helped.

 

Thanks

 

View solution in original post

12 REPLIES 12

JagjeetSingh
Kilo Sage

Hi,

What do you mean by single score here. Are you using Data Visualization component here. More details on this are going to be helpful.

 

 

 

 

Jagjeet Singh
ServiceNow Community Rising Star 2022/2023

Hi,

Yes, I use Data Visualization component.

 

Nootan Bhat
Mega Sage

Hi @Nadia7,

You can't use the dynamic values in data visualization filters. You have to use script or parFilters.

 

1) You can use the parFilters. Refer: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1156652. Tried it in PDI and it works.

 

2)  Or else you can use the scripts in your data visualization.

Below are the sample script(use the appropriate values in the script):

In your data resources use below script:
function evaluateProperty({api, helpers}) {
  var data = [
                {
                    "isDatabaseView": false,
                    "allowRealTime": true,
                    "sourceType": "table",
                    "label": {
                        "message": "LABEL OF YOUR DV"
                    },
                    "tableOrViewName": "TABLE_NAME",
                    "filterQuery": "YOUR_FILTER"+api.data.look_up_records.result , //you can build your query here using dynamica data binding.  
                    "id": "DVID"
                }
            ];
	return data;
}

 

Metric use below code:

 

function evaluateProperty({
    api,
    helpers
}) {
    var metric = [
                {
                    "dataSource": "DVID",
                    "id": "METRICID",
                    "aggregateFunction": "SUM",
                    "aggregateField":"FIELD_NAME",
                    "numberFormat": {
                        "customFormat": false
                    },
                    "axisId": "primary"
                }
            ];
    return metric;
}

 

In Group by use below code:

function evaluateProperty({
    api,
    helpers
}) {
    var groupby = [{
        "maxNumberOfGroups": "ALL",
        "numberOfGroupsBasedOn": "NO_OF_GROUP_BASED_ON_PER_METRIC",
        "showOthers": false,
        "groupBy": [{
            "dataSource": "DVID",
            "groupByField": "FIELD_NAME",
            "isRange": false,
            "isPaBucket": false
        } ] //can use multi 'group by' by adding another object 
    }];
    return groupby;
}

 

This way you can filter the data the way you want. For field, query etc use the state or data parameters to bind the data dynamically.

 

Please let me know if it worked for you.

 

 

Thanks

 

Thank you @Nootan Bhat ,

I am trying to do it with script, but I get an error. Maybe you can help me with it? 

data_viz.png