Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Bind client state parm into filter of a multi data source VIZ OOB, to render a timeseries-UI Builder

Sharique Azim
Mega Sage

I’m building a dynamic cost‑visualization dashboard in UI Builder that lets stakeholders:

  • Select a manager from the UI (Type ahead sets a client state param).

  • As they choose, the dashboard shows that manager’s users’ cost against the total cost of all users.

The data comes from the custom table u_sw_license_user_alloc_archive, which has fields like:

 

Field NameField TypeReference Table if applicable
u_reporting_date  glide_date 
u_cost currency 
u_allocation_status string/choice 
u_licensed_by reference asset
u_user referencesys_user

 

                                                                 🛠The configuration that is working for me:


I am able to generate the same timeseries area chart if i chose the table with fixed query data sources .

The second data source has a fixed  filter query that returns an array of sys id from a script include , where I am passing the sys id of the user [which is static and hardcoded at this point]

 

//filters like
user.sys_id >IN > javascript: new CustSwLicClientUtils().NestedSysIds('29c3b4378b8010207243fddc4bcbb4')

//this is a client callable  script include that returns values properly and correctly✅

 

 

The timeseries chart looks like this which is perfect, with two data primarily, total company cost and cost among colleagues under same manager.

 

ShariqueAzim_2-1759171152785.png


                                                           

 

                                                                            My configuration  so far:

____________________________________________________________________________________

 

ShariqueAzim_0-1759170873243.png

ShariqueAzim_1-1759170910766.png

 

 

                                                            Problem starts from here 👇🏼

___________________________________________________________________________________

  • In the filter of the second data source

ShariqueAzim_3-1759171828590.png

 

 

 

  • As you can see below that there is no option to bind 🛢️ the client state directly in the filter of the data source of the visualization component.

ShariqueAzim_4-1759171923628.png

 



🥅What I am trying to achieve is convert the static fixed query to dynamic.

To achieve this, I’ve defined a multi source viz data resource with two visualizationIds following this doc link

 

🔗ServiceNow Docs-Local data instances for multiple visualizations :

 

 

  • Created a Data resource ->  Data Visualization API for multiple data visualizations

    ShariqueAzim_0-1759225542491.png
  • vis_active_trendSUM of u_cost over u_reporting_date with no filter query (single line) trend by reporting date.

  • vis_inactive_trend_by_licensed_bySUM of u_cost over u_reporting_date where i want call a script include i.e. as mentioned above , grouped by u_licensed_by (multiple lines). Similar to my already generated chart.

Here’s the JSON I was able to generate  so far:

 

[
  {
    "details": {
      "visualizationId": "vis_active_trend",
      "followFilter": true
    },
    "configurations": {
      "dataConfigurations": [
        {
          "sourceType": "table",
          "dataCategory": "trend",
          "order": 0,
          "tableOrViewName": "u_sw_license_user_alloc_archive",
          "aggregateFunction": "SUM",
          "aggregateField": "u_cost",
          "trendBy": "u_reporting_date",
          "trendInterval": "date",
          "removeMissingIntervalData": false
        }
      ]
    }
  },
  {
    "details": {
      "visualizationId": "vis_inactive_trend_by_licensed_by",
      "followFilter": true
    },
    "configurations": {
      "dataConfigurations": [
        {
          "sourceType": "table",
          "dataCategory": "trend",
          "order": 0,
          "tableOrViewName": "u_sw_license_user_alloc_archive",
          "aggregateFunction": "SUM",
          "aggregateField": "u_cost",
          "trendBy": "u_reporting_date",
          "trendInterval": "date",
          "removeMissingIntervalData": false,
          "filterQuery": "u_user.active=true", // im doubtful on this. but  kept for testing
          "groupBy": ["u_licensed_by"]
        }
      ]
    }
  }
]

 



Essentially, I want the filterQuery to be recomputed whenever the client state changes, so the chart refreshes automatically.

 

 

I’ve seen these related threads:

Those examples show how to shape a single data source , but I haven’t found a clear way to bind a dynamic filter condition into a multi data source data visualization like mine.

 

Please advice.

 

Regards,

Shariq

1 REPLY 1

SiddhardhaN7964
Tera Guru

hi @Sharique Azim  - I am successful using below approach.

  • Create Client State parameter for 'Data Visualization API for multiple data visualizations' Requests configuration.
  • Bind the client state parameter in data resource.
  • For the event where you want to dynamically change the filter - write script to update the state parameter.
  • Refresh your data resource.