logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
sealfan  
#1 Posted : Wednesday, October 19, 2016 7:20:28 PM(UTC)
sealfan

Rank: Member

Groups: Registered
Joined: 9/4/2015(UTC)
Posts: 23
Canada
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?
epf  
#2 Posted : Thursday, October 20, 2016 9:02:59 AM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 836
Switzerland

Thanks: 14 times
Was thanked: 142 time(s) in 136 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
thanks 1 user thanked epf for this useful post.
sealfan on 10/20/2016(UTC)
sealfan  
#3 Posted : Thursday, October 20, 2016 3:26:13 PM(UTC)
sealfan

Rank: Member

Groups: Registered
Joined: 9/4/2015(UTC)
Posts: 23
Canada
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)
Users browsing this topic
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.