Seal Report Forum
»
Report Edition
»
Reports
»
Use ENUM Value For Email Subject
Rank: Member
Groups: Registered
Joined: 9/4/2015(UTC) Posts: 23 Location: ottawa Thanks: 7 times Was thanked: 2 time(s) in 2 post(s)
|
In a previous post we discussed how to set the email subject using a restriction value (See "Use Restriction Value as Parameter in Email Subject Output") For that I would use this code in the Pre-generation script of the email output Device Code:@using Seal.Model
@{
ReportOutput output = Model;
var restriction = output.Report.Models[2].Restrictions.FirstOrDefault(i => i.DisplayNameEl == "EmailBuild");
if (restriction != null)
{
output.EmailSubject = "Performance Test Results for " + restriction.GetEnumDisplayValue(restriction.EnumValues[0]);
}
string result = "1"; //Set result to 0 to cancel the report.
}
@Raw(result)
What if I don't want to use a restriction value but rather a value I generate from SQL dynamically using an ENUM query or something similar. My goal would be to have the same functionality as using a restriction value in the email header but I don't want to have to manually select the restriction value at runtime as I will be triggering this report from cmdline and sending email output. If I use a restriction I have to execute the report, prompt for restriction value, select restriction, and run. What are your thoughts?
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 12/20/2013(UTC) Posts: 1,209 Thanks: 14 times Was thanked: 206 time(s) in 199 post(s)
|
Well, actually you can do what you want with your C# script, if you want to query your database, below is a small sample made on Northwind (it can be adapted to work in all scripts) Code:@using Seal.Model
@using System.Data.OleDb;
@{
ReportOutput output = Model;
var connection = output.Report.Sources[0].Connection.GetOpenConnection();
//OR you can build your own connection (Note that it might be an OdbcConnection)
//var connection = new OleDbConnection(output.Report.Sources[0].Connection.FullConnectionString);
//connection.Open();
var command = connection.CreateCommand();
command.CommandText = "select lastname from employees";
var selectResult = command.ExecuteScalar();
output.Report.LogMessage("MY SELECT result => " + selectResult.ToString());
string result = "1"; //Set result to 0 to cancel the report.
}
@Raw(result)
I hope it helps
|
1 user thanked epf for this useful post.
|
|
|
Rank: Member
Groups: Registered
Joined: 9/4/2015(UTC) Posts: 23 Location: ottawa Thanks: 7 times Was thanked: 2 time(s) in 2 post(s)
|
Used this and it works great. Many thx! Code:@using Seal.Model
@using System.Data.OleDb;
@{
ReportOutput output = Model;
var connection = output.Report.Sources[0].Connection.GetOpenConnection();
var command = connection.CreateCommand();
command.CommandText = "SELECT TOP 1 ....... ORDER BY 1 DESC";
var selectResult = command.ExecuteScalar();
output.Report.LogMessage("MY SELECT result => " + selectResult.ToString());
if (selectResult != null)
{
output.EmailSubject = "Email Subject Start... " + selectResult.ToString();
}
string result = "1"; //Set result to 0 to cancel the report.
}
@Raw(result)
|
|
|
|
Seal Report Forum
»
Report Edition
»
Reports
»
Use ENUM Value For Email Subject
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.