Sometimes it may be useful for a single form template to conditionally generate a specific custom report from a collection of possible reports. In the example outlined below, for instance, two custom reports will be defined and depending on whether the user is choosing an "Initial Inspection" or a "Re-Inspection".
First, create a form that has field(s) as usual including field(s) that will be the decision point as to what report should be generated and emailed:
Next, add two different reports to the form and add field bindings as usual:
Since we want to email the report to someone, add a mail notification as normal. When you do so, add both of the custom reports to the notification:
If you were to use the form as-is, it would produce and email both reports. To prevent this, you will need to add a little bit of server script code. Handle the ServerQueuing event and in it, tell the server that the report you do not want to send is already complete as follows:
' Triggered when an app changes user queues <MiCode(FormScriptEventType.ServerQueuing)> _ Public Sub Form_ServerQueuing(ByVal e As ServerQueuingEventArgs) if _InspectionType.Value = "Initial" then RecordExportResult("Report - Re-Inspection Report", true, "", "", "") else if _InspectionType.Value = "Re-Inspection" then RecordExportResult("Report - Certificate of Inspection", true, "", "", "") end if End Sub
This code "tricks" the server into thinking the report has already been created and will prevent it from actually creating that report. The mail notification will detect that only one of the two reports that were attached actually exists and will only send that one.