Adding a parameter

Top  Download  Previous  Next

To the Devices ranked by number of events report, you will add a parameter with the minimum number of events that must occur on a device for the device to appear in the results. The types of parameters (report parameters and query parameters) are described in Report creation in the designer.

1.In the pane on the right, on the Data tab, in the Parameters section, open the form of a new report parameter.

en_rep_edit-parameter_new-parameter_01_zoom8

2.Fill in the form.

en_rep_edit-parameter_parameter-form_01_zoom38

3.On the Data tab, in the data source section, select the events_logs table and open the Data Source Wizard window.

en_rep_edit-parameter_data-source-wizard_01_zoom8

4.Write a new SQL query that uses the value of the query parameter:

SELECT

l.device_id,

max(coalesce(d.device_type_id, l.device_type_id)) AS device_type_id,

max(t.device_name) AS device_name,

COUNT(1) AS events_count

FROM report.alert_event_logs l

LEFT JOIN report.devices d ON l.device_id = d.id

JOIN LATERAL (

SELECT

CASE

WHEN d.id is NOT NULL

THEN d.full_name

ELSE l.device_full_name

END

AS device_name

) t ON true

WHERE l.start_date >= @event_date_from::timestamp

AND l.start_date <= @event_date_to::timestamp

AND (

@map_id::int IS NULL OR

@device_ids != '' OR

EXISTS(

SELECT 1 FROM report.maps_devices md

WHERE md.device_id = l.device_id AND md.map_id = @map_id::int

)

)

AND (

@device_type_ids = ''

OR @device_ids != ''

OR l.device_type_id = ANY(string_to_array(@device_type_ids, ',')::int[])

)

AND (

@device_ids = '' OR

l.device_id = ANY(string_to_array(@device_ids, ',')::int[])

)

AND (

@event_ids = ''

OR COALESCE(l.alert_event_id, 0) = ANY(string_to_array(@event_ids, ',')::int[])

)

GROUP BY l.device_id

HAVING count(1) > @events_count

ORDER BY

CASE WHEN @sort_direction = 'ASC' THEN count(1) END ASC,

CASE WHEN @sort_direction = 'DESC' THEN count(1) END DESC

LIMIT (@records_count::int)

5.Replace the existing query with the new one.

en_rep_edit-parameter_sql-query-replace_01_zoom39

6.Add the query parameter used in the query. Its value is an expression that returns the number entered in the report parameter.

en_rep_edit-parameter_query-parameter_01_zoom40

en_rep_edit-parameter_query-parameter_02_zoom40

en_rep_edit-parameter_query-parameter_03_zoom39

7.Add the parameter to the list in the report header and adjust its style.

en_rep_edit-parameter_parameter-in-report-header_01_zoom16

8.Set the value of the parameter.

en_rep_edit-parameter_parameter-value_01_zoom16

en_rep_edit-parameter_parameter-value_02_zoom39

9.Check the report preview. The parameter label needs a translation – see Language versions of reports.

en_rep_edit-parameter_preview-untranslated-label_01_zoom17

10.In the side menu, select the Localization section and set the language.

en_rep_edit-parameter_localization-language_01_zoom16

en_rep_edit-parameter_localization-language_02_zoom16

11.Fill in the label and the description of the parameter in this language.

en_rep_edit-parameter_label-translation_01_zoom18

12.Check the report preview again – the parameter works and is displayed correctly.

Next: Adding a chart.