Data Sources - Scripting
The Script data source allows you to add additional data into a report. Script data sources are able to reference data keys from other data sources. This allows you to modify keys from one data source, and return a new altered data source.
Example
Say we have a query data source named "Area Data" which contains four columns: month, north_area, south_area, and t_stamp. If we need to build a new data source without the t_stamp coulmn we can use the following code:
#build a header and initialize a pydataset
header
=
[
'month'
,
'north_area'
,
'south_area'
]
filteredDataset
=
[]
#get the results from the Area Data data source
rawDataset
=
data[
'Area Data'
].getCoreResults()
#build the new pydataset out of only some of the Area Data's data keys
for
row
in
range
(rawDataset.rowCount):
valCategory
=
rawDataset.getValueAt(row,
'month'
)
valNorthArea
=
rawDataset.getValueAt(row,
'north_area'
)
valSouthArea
=
rawDataset.getValueAt(row,
'south_area'
)
filteredDataset.append([valCategory,valNorthArea,valSouthArea])
#convert the pydataset to a standard dataset
filteredDataset
=
system.dataset.toDataSet(header, filteredDataset)
#create a new data source with the filtered results
data[
'updated Area Data'
]
=
filteredDataset
The above code would create a new data source in the Design panel named 'updated Area Data'. Note that .getCoreResults() is only applicable when the raw data source is a query. If 'Area Data' in the example above was a static CSV then you could get the data into a 'new data source' with the following:
data[
'new data source'
]
=
data[
'Area Data'
]