Forum Discussion

Astroraf's avatar
Astroraf
Data Pipeline
10-29-2025
Solved

Querying Model in Text Widgets?

Hi DRay​ Liliia_DevX​    Is it possible to query your model in a text widget to display a value? For example say I have a text widget that says Total Revenue: {Total Revenue} this part coming f...
  • harikm007's avatar
    10-31-2025

    Hi
    As you know, the Text widget in Sisense doesn’t allow adding dimensions or measures directly, so there’s no built-in way to display dynamic values like {Total Revenue} out of the box. However, this can be achieved using a small custom script.

    Here’s one approach you can try:

    Create a Text Widget and add your desired text in the widget, for example: This year revenue: {Total Revenue}.
    We’ll use a script to replace {Total Revenue} with the actual value from your model.
    Add the following script to your widget:

    widget.on('domready', function(w, args){
    const textToReplace = '{Total Revenue}'
    const result = getMeasure(args.widget);
    args.widget.style.content.html = args.widget.style.content.html.replace(textToReplace, result.values[0].text);
    })
     
    function getMeasure(widget) {
      const query = {
        "datasource": widget.datasource,
        "metadata": [
          {
            "jaql": {
    "type": "measure",
    "formula": "[3DDF8-AEA]",
    "context": {
    "[3DDF8-AEA]": {
    "table": "sales_revenue",
    "column": "amount",
    "dim": "[sales_revenue.amount]",
    "datatype": "numeric",
    "columnTitle": "amount",
    "tableTitle": "sales_revenue",
    "agg": "sum",
    "title": "sum of amount"
    }
    },
    "title": "[sum of amount]",
    "columnTitle": "[sum of amount]"
    }
            
          }
        ]
      };
      return runHTTP(query);
    }
     
     
    function runHTTP(jaql) {
      const $internalHttp = prism.$injector.has("base.factories.internalHttp") ?
      prism.$injector.get("base.factories.internalHttp") : null;
     
      const ajaxConfig = {
        url: "/api/datasources/" + encodeURIComponent(jaql.datasource.title) + "/jaql",
        method: "POST",
        data: JSON.stringify(jaql),
        contentType: "application/json",
        dataType: "json",
        async: false
      };
      const httpPromise = $internalHttp ? $internalHttp(ajaxConfig, true) : $.ajax(ajaxConfig);
     
      return httpPromise.responseJSON;
    };



    Replace the value of textToReplace with the placeholder text you want to replace in your widget.

    In the script above, replace the query object with the JAQL you want to execute.
    If you need to use a more complex calculation, you can get the exact JAQL by creating a temporary Indicator Widget and adding your formula in the Primary panel.
    Then, in your browser console, run: prism.activeWidget.metadata.panels[0].items[0].jaql
    Copy the JAQL object from the console output and use it in query variable in the script.

    Then, save the script and refresh the dashboard.
    Result:



    If you prefer a simpler, no-code approach, you can use the Paldi Advanced Text Widget plugin.
    It allows you to:

     - Add rich text, images, and HTML content
     - Display dynamic values and dimensions directly
     - Avoid custom scripting

    This is often the most efficient and flexible solution for dynamic text in dashboards.
    https://www.paldi.solutions/sisense-plugins/advanced-text-widget

    Please let me know if you have any questions

    -Hari