The CreatorCon Call for Content is officially open! Get started here.

UI Builder Script Data Source - Set Color Rules

Lucas Occhiutto
Tera Contributor

Hello!


I need to come up with a script to set a custom single color rule for a Single Score Interaction on UI Builder. But I didn't find any documentation about the necessary data to return in the evaluateProperty function. 

 

My goal is to be able to set a color rule based on the data source (also scripted) count output I have for my single score interaction. 

 

Single Score Interaction Data Source Script:

function evaluateProperty({api,helpers}) {
    // Query CoE
    var coeList = api.state.listSysIdCoE;
    var coeQuery = "";
    
    coeList.forEach(function(sysId, index, coeArray){
        coeQuery += "u_service_offering="+sysId;
        coeQuery += (coeArray.length - 1 != index) ? "^0R" : "";
    });

    //Query concatenation
    var strQuery = "stateNOT INclosed_complete,closed_abandoned^"+ api.state.strQueryAssignment + "^" + coeQuery + "";

    console.log(strQuery);
    
    //Output
    
    var data = [{
        "isDatabaseView": false,
        "allowRealTime": true,
        "sourceType": "table",
        "label": {
            "message": "Interações em Aberto"
        },
        "tableOrViewName": "interaction",
        "filterQuery": "" + strQuery + "",
        "id": "dataInteractionID"
    }];
    
    return data;
}

Metric Script:

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

 

if I use the static input of the color rules (for single color option), something happens with the data comparison of the data source output and the color rule, which causes the single score output to be "--"; 

LucasOcchiutto_0-1676304572563.png

So I need to find a way to manipulate the data output from the data source, or manage to compare it correctly through the color rule using a script.


Thanks in advance!

3 REPLIES 3

Nootan Bhat
Kilo Sage

Hi @Lucas Occhiutto ,

please use the "debugger" in the data source script and check what are you getting for 

api.state.strQueryAssignment

and 

coeQuery

 

While building "strQuery" you are directly using the api.state.strQueryAssignment, and not checking this to any field value. I hope this state parameter is return value in this format "type=chat", if not update the query parameter correctly to get the right data.

 

Let me know if it helped.

 

Thanks

@Nootan Bhat  Thank you. How can I find documents regarding scripted data source and metrics. I need the script for data source with indicator type.

babaei503
Tera Contributor

@Lucas Occhiutto Thank you. How can I find documents regarding scripted data source and metrics. I want script for data source with indicator type.