cancel
Showing results for 
Search instead for 
Did you mean: 
TriAnthony
Sisense Team Member
Sisense Team Member

Input Parameters using BloX for What-If Analysis

This is an alternative to the paid or community Input Parameter plugins.

This new BloX Input Parameter custom action:

  • supports multiple levers (input parameters) with just one Apply button
  • supports all widget types
  • remembers previous selections even after refreshing/closing the dashboard
  • loops through all widgets so dashboard designers do not have to specify widget IDs in the BloX code. Note: Be mindful of performance when considering this option as this will execute the BloX action on all widgets including those that the input parameters may not necessarily be relevant to.

TriAnthony_0-1696342444534.png
 
Instructions:
  • Import the example dashboard attached below. Before importing the file, change the file extension from .txt to .dash. Make sure that you still have the Sample ECommerce Elasticube for this dashboard to properly display the data.
  • Open the Lever Configuration widget (or any BloX widget), then add the custom action given below to your Sisense environment.
    • Go to the Actions tab, click the three-dot menu, then click Create Action.
    • Copy the custom action code from below and paste it into your BloX custom action editor.
    • Give this name for the action: ParameterSwap_V2_AllWidgets. You can also use a different name, but make sure the name of the action matches with the name referenced in the BloX code.
    • Click Next, then Create.
  • Click the Apply button to close the widget.
  • Enter values to the levers and click Apply. The number on the widgets is now recalculated based on your input.

There are currently three input parameters in this example. To add another input parameter:

  • In the BloX code of the Lever Configuration widget, modify the number of input parameters in the BloX code under the paramsToModify parameter. For example, if you need 4 input parameters (levers), update the value to 4.

        TriAnthony_2-1696346104586.png

  • On the left panel, add the additional swap_levers to the Values panel, i.e. swap_lever4, swap_lever5, etc. You can assign any arbitrary hard-coded number to these swap levers.

          TriAnthony_6-1696346401759.png

  • To add the input box to the widget, copy one of the column elements then add it to the BloX code. Modify the id parameter to selectVal<lever number>, e.g. if this is the fourth lever, the id should be selectVal4. Similarly, modify the value parameter to match the swap_lever name you added in the previous step, e.g. [swap_lever4]. Update the title text as well and give it a meaningful description.

    TriAnthony_8-1696347177772.png
  • Save the widget by clicking the Apply button.
  • Add the additional levers to your widget formulas as needed so that they get recalculated when you enter the input values.

BloX action:

 

 

 

//initialize variables
var swapParam = [];

//create an array of swap_levers
for (d = 0; d < payload.data.paramsToModify; d++) {
    swapParam[d] = "swap_lever" + (d + 1);
}

//loop through each of the specified widgets
payload.widget.dashboard.widgets.$$widgets
    //.filter(i => i.oid != payload.widget.oid)
    .forEach(function (widget) {

        //loop through each panel in the widget
        //exclude the filter panel (last panel)
        for (p = 0; p < widget.metadata.panels.length - 1; p++) {

            //loop through each item in the panel
            for (i = 0; i < widget.metadata.panels[p].items.length; i++) {

                //check if the panel item contains context (i.e. a formula)
                if (widget.metadata.panels[p].items[i].jaql.context != undefined) {
                    var queryContext = widget.metadata.panels[p].items[i].jaql.context;

                    //loop through each context in the item
                    for (let [k, v] of Object.entries(queryContext)) {

                        //loop through each swap_lever
                        for (s = 0; s < swapParam.length; s++) {

                            //check if the formula contains the swap_lever
                            if (v.title == swapParam[s]) {
                                var val = 'selectVal' + (s + 1);

                                //update the formula with the swap_lever value that the user entered
                                v.formula = payload.data[val];
                            }
                        }
                    }
                }
            }
        }

        //apply and save changes to the widget
        widget.changesMade('plugin-BloX', ['metadata'])

        //refresh the widget
        widget.refresh();
    })

 

 

We hope this is a helpful article and would love to hear about your experience in the comments! 

 

Version history
Last update:
‎10-24-2023 10:58 AM
Updated by:
Contributors
Community Toolbox

Recommended quick links to assist you in optimizing your community experience:

Developers Group:

Product Feedback Forum:

Need additional support?:

Submit a Support Request

The Legal Stuff

Have a question about the Sisense Community?

Email [email protected]

Share this page: