Report formulas
No output
This formula specifies no report output. When the report is run, the default message specified in the Run Message field will be shown.
output = New Hansen.Core.Reports.FormulaOutput()
Return Result.Success
No output with message
This formula also specifies no report output, but it shows a custom message rather than the default message from the Run Message field.
This example also shows how the formula can include the values of parameters defined in the
Reports Manager. In this case, PrimaryKey
is a component list parameter
that points to the primary key of the component for the page that the report is attached to.
For example, if the report is attached to the Building Application InfoViewer, then the
primary key is BuildingApplication.BuildingApplicationKey
.
Dim primaryKey As Integer = input.Parameters.Item("PrimaryKey")
output = New Hansen.Core.Reports.FormulaOutput()
output.NoOutputRunMessage = "Custom message " & primaryKey.ToString()
Return Result.Success
No output with multiple keys
This formula also specifies no report output. It is similar to the previous example, but it shows how a report formula can include the primary keys of multiple records selected from a lookup grid or from the Map Browser.
Dim primaryKeys As List(Of Object) = new List(Of Object)
if TypeOf input.Parameters.Item("PrimaryKey") Is List(Of Object) Then
primaryKeys = input.Parameters.Item("PrimaryKey")
Else
primaryKeys.Add(input.Parameters.Item("PrimaryKey"))
End If
Dim keys As String = ""
For Each item As Object In primaryKeys
keys &= item.ToString() & ", "
Next
If Not keys.IsNullOrWhiteSpace() Then
keys = keys.Substring(0, keys.Length - 2)
End If
output = New Hansen.Core.Reports.FormulaOutput()
output.NoOutputRunMessage = "Custom message " & keys
Return Result.Success
Send a notification
This formula sends a notification to the primary applicant on a building application.
Dim res As Result = Result.Success
Dim primaryKey As Integer = input.Parameters.Item("PrimaryKey")
Dim app = ServerApplication.NewComponent(Of Hansen.CDR.Building.IBuildingApplication)
app.PrimaryKey = primaryKey
res = app.LoadByKey()
res.Assert()
Dim primary As Hansen.CDR.Building.IApplicant
res = app.Applicants.GetPrimaryApplicant(primary)
res.Assert()
Dim contact = primary.Contact
res = Hansen.Resources.Notifications.NotificationService.Send
("Test Message", "SBCUSTOM", app, contact)
res.Assert()
output = New Hansen.Core.Reports.FormulaOutput()
output.NoOutputRunMessage = "Custom message " & primarykey.ToString()
return res
Another report
This formula shows a report that is configured in the Reports Manager under the Name property of the report request specifies the name of the general report, and the ExportType property specifies the output.
node. TheDim result as Result = Result.Success
Dim primaryKey As Integer = input.Parameters.Item("PrimaryKey")
Dim reportRequest = new Hansen.Core.Report.Management.ReportRequest()
reportRequest.Name = "CustomReport"
reportRequest.ExportType = "pdf"
reportRequest.Parameters.Add("ApplicationKey", primaryKey)
Dim reportService = ServerApplication.Resolve
(Of Hansen.Core.Report.Management.IReportManagementService)
Dim reportResponse As Hansen.Core.Report.Management.ReportResponse =
reportService.Generate(reportRequest)
output = New Hansen.Core.Reports.FormulaOutput()
output.OutputStream = reportResponse.OutputStream
output.ContentType = reportResponse.ContentType
output.Filename = reportResponse.Filename
Return result
Notification with attachment
This is similar to the previous example, but the report is sent as an email attachment.
Dim result as Result = Result.Success
Dim primaryKey As Integer = input.Parameters.Item("PrimaryKey")
Dim reportRequest = new Hansen.Core.Report.Management.ReportRequest()
reportRequest.Name = "CustomReport"
reportRequest.ExportType = "pdf"
Dim application = ServerApplication.NewComponent
(Of Hansen.CDR.Building.IBuildingApplication)
application.PrimaryKey = primaryKey
result = application.LoadByKey()
result.Assert()
Dim primary As Hansen.CDR.Building.IApplicant
result = application.Applicants.GetPrimaryApplicant(primary)
result.Assert()
reportRequest.Parameters.Add("ApplicationKey", primaryKey)
Dim reportService = ServerApplication.Resolve
(Of Hansen.Core.Report.Management.IReportManagementService)
Dim reportResponse As Hansen.Core.Report.Management.ReportResponse =
reportService.Generate(reportRequest)
Dim contact = primary.Contact
Dim message As New Hansen.Resources.Notifications.NotificationMessage
(Nothing, "Test Message", application, "DEFINED_NOTIFICATIONTYPE", Nothing, Nothing)
message.ReferenceContact = contact
Dim attachment = new System.Net.Mail.Attachment(reportResponse.OutputStream,
reportResponse.Filename)
message.Attachments.Add(attachment)
result = Hansen.Resources.Notifications.NotificationService.Send(message)
result.Assert()
output = New Hansen.Core.Reports.FormulaOutput()
output.NoOutputRunMessage = "Report has been emailed to the primary applicant."
Return result