How to pass a dataset from a window to a report?

I have a dataset on my window and I want to pass that dataset to a report parameter. Upon searching the forum I found this post: Generating a report from window components - #6 by ethomason

I tried to create a parameter (Parameter type is dataset). I just replicated step 1 and step 2 from the post:

New Parameter

I got an error:
WARN: Parameter “KWHdataset” missing default value expression.

WARN: Error invoking script.Traceback (most recent call last):
File “function:updateData”, line 3, in updateData
KeyError: KHWdataset

How am I suppose to do this? Is there a better way to do this?

If the dataset already exists on the window and is being passed to the report, you don’t need the Script datasource in the report. To get a default dataset in KWHdataset, add something like the following to the Default Value (expression) box when KWHdataset is selected… Commas, quotes, brackets, etc. all matter, start with something very simple, then expand to look like the expected dataset.

runScript('system.dataset.toDataSet(' +
    '["header_1", "header_2"]' +
    ',[' +
    ' [row_1_col_1, row_1_col_2],'
    ' [row_2_col_1, row_2_col_2],'
    '])')
1 Like

Another option is to make a dataset tag with the structure of your final data - you can then use that as sample data while building your report.

1 Like

This works for me. A few corrections on your sample code:

runScript('system.dataset.toDataSet(' +
    '["header_1", "header_2"]' +
    ',[' +
    ' ["row_1_col_1", "row_1_col_2"],' +
    ' ["row_2_col_1", "row_2_col_2"],' +
    '])')