I have a single select parameter that I define in a data studio community connector in getConfig() as below. The parameter is then used as a dropdown data control in the report.
config
.newSelectSingle()
.setId("characteristic_selected")
.setName("Characteristic selected")
.addOption(
config
.newOptionBuilder()
.setLabel("a")
.setValue("a")
)
.addOption(
config
.newOptionBuilder()
.setLabel("b")
.setValue("b")
)
.addOption(
config
.newOptionBuilder()
.setLabel("c")
.setValue("c")
)
.addOption(
config
.newOptionBuilder()
.setLabel("d")
.setValue("d")
)
.addOption(
config
.newOptionBuilder()
.setLabel("e")
.setValue("e")
)
.setAllowOverride(true);
In getFields() I define Characteristic which then returns data from the database a, b, c, d or e:
fields.newDimension()
.setId('Characteristic')
.setType(types.TEXT);
I am trying to define a calculated field which I will then use as a filter in my charts and tables to only display data for the option selected by the user in the dropdown data control. E.g. if the user selects "b", then only data labelled "b" for Characteristic will display.
My attempt (inspired by the answer here: How to use a Parameter in calculated field defined in getFields() (Google Data Studio Community Connector)?) is:
fields.newDimension()
.setId('Characteristic calc')
.setDescription('Sets true if characteristic selected in dropdown is the same as the characteristic dimension field')
.setFormula('$Characteristic = "' + request.configParams.characteristic_selected + '"')
.setType(types.BOOLEAN);
I then apply a filter to the tables and charts only include Characteristic calc = True
The default is "a". When I first load the page, the data filters correctly and only displays "a". However when I select "b" from the dropdown data control, it still only displays data for "a". It appears that the code does not capture the updated configParam when changed in the report.
Note: if I set the calculated field up in the report as opposed to in the data studio connector, then it works correctly. I use the connector in lots of reports however, so it is annoying to have to create the calculated field each time I create a new report.