Forum Discussion

Astroraf's avatar
Astroraf
Data Integration
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 from your model?

I know this can be achieved in BloX but BloX does not work with Compose SDK so I am trying to see if this works in a text widget. 

 

 

  • 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

5 Replies

  • Liliia_DevX's avatar
    Liliia_DevX
    Sisense Employee

    Astroraf​ Hi 🙃,

    According to our dev team, there is no need to query data inside a text widget. Instead, load the data with a separate useExecuteQuery hook (example on playground). You can also render this data in any format anywhere on the page. If you need to inject a new widget to the existing dashboard on the fly, you can add a new widget (e.g., TextWidget with a static data-string) like in this example.

    Even a better option is to create your own custom widget (example) with any data visualization you need. CustomWidget is a much more powerful and flexible solution and is a direct replacement for the BloX plugin in the Sisense native application. 

    Hope that helps!

    • Astroraf's avatar
      Astroraf
      Data Integration

      Hi Liliia_DevX​ 

      But if I am just embeeding Sisense dashboard via Dashboard ID or by Widget ID, then is there a way to query the data in a text field box?

      • Liliia_DevX's avatar
        Liliia_DevX
        Sisense Employee

        Astroraf​ Thanks for your reply. What do you mean by embedding in this case? Please describe your use with ComposeSDK to provide you with the proper suggestions.

  • harikm007's avatar
    harikm007
    Data Warehouse

    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