How do we read and write report parameters and variables in javascript event callbacks?

jmoritz
edited February 11, 2022 in Analytics #1

There doesn't seem to be any way to access the vars or params objects in javascript events, or even the reportContext object.

Best Answer

  • jfranken
    #2 Answer ✓

    Attached is an example that shows how to reference parameters in onContentUpdate. The two client scripts run in the browser so they work differently than the engine scripts. Any values you want to access in the browser need to be passed to it. One way to do that is to create a text element. In the attached example, I set the Text element type (top middle of the edit window) to HTML. I passed the two parameter values to two browser window variables in the Text element script: window.param1 and window.param2 where "window" is the standard DOM browser to level element. I also added two

    <

    div> tags to display the values that were passed to the browser so you can see that it works, but they are not required. In onContentUpdate I wrote some simple code to display the values in the divs.

    Regarding the custom visualization question, I believe that is being handled on a support ticket.

    Warning No formatter is installed for the format ipb

Answers

  • To access parameters in events, try the following:

    params["param_name_here"].value

    In an event handler, you can also type:

    reportContext.

    Be sure to include the trailing dot. You should see a popup window showing the methods and sub-objects for the reportContext object..

    Warning No formatter is installed for the format ipb
  • Thanks, Jeff. I've tried this. For example, in the report's onContentUpdate, both vars and params are undefined. It's annoying not to have them there, but where I really need them is in scripting for custom visualizations.

  • jfranken
    #5 Answer ✓

    Attached is an example that shows how to reference parameters in onContentUpdate. The two client scripts run in the browser so they work differently than the engine scripts. Any values you want to access in the browser need to be passed to it. One way to do that is to create a text element. In the attached example, I set the Text element type (top middle of the edit window) to HTML. I passed the two parameter values to two browser window variables in the Text element script: window.param1 and window.param2 where "window" is the standard DOM browser to level element. I also added two

    <

    div> tags to display the values that were passed to the browser so you can see that it works, but they are not required. In onContentUpdate I wrote some simple code to display the values in the divs.

    Regarding the custom visualization question, I believe that is being handled on a support ticket.

    Warning No formatter is installed for the format ipb
  • Thanks, Jeff. That answers part of the question. I'm going to try the trick with an empty text element and see how it goes.