Batch Email Part 2

Stimulsoft Reports.WEB discussion
Post Reply
JohnW
Posts: 103
Joined: Mon Nov 20, 2017 8:29 pm

Batch Email Part 2

Post by JohnW »

In my effort to read report data I have been attempting to work with the suggestion from this thread
viewtopic.php?t=60976

In my report I created a read only variable called 'varEmail'. I assigned it a value of of data field from the query called 'newLicenseReport.email'.

On the report for testing purposes I have used the varEmail and it shows the correct data. Good so far.

In my code (VB.net) I added this test line of code to see if I could extract the value for the email.

Code: Select all

Dim xx As String = report.Dictionary.Variables("varEmail").Value
What is being returned is the name of the data field 'newLicenseReport.email' and not the email address on the report. I am looking for the proper syntax to extract the email address showing on the report.

Again I desire to use this in a send to address for mail message. I plan on sending a batch of dozens of the emails each day.

Any suggestions? This should be simple but I have been unable to figure it out to this point.

Thanks

John W
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: Batch Email Part 2

Post by Lech Kulikowski »

Hello,

Please send any sample report with test data or sample project for analysis.

Thank you.
JohnW
Posts: 103
Joined: Mon Nov 20, 2017 8:29 pm

Re: Batch Email Part 2

Post by JohnW »

I have the sample/test project to support.
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: Batch Email Part 2

Post by Lech Kulikowski »

Hello,

Ok. We will reply to you by email.

Thank you.
JohnW
Posts: 103
Joined: Mon Nov 20, 2017 8:29 pm

Re: Batch Email Part 2

Post by JohnW »

I am getting closer. I have been able to iterate the report data. I have been able to collect the email address and then filter the report data using a variable.

What I am now unable to do it create the report for each loop, save it to a .pdf file for emailing. When I run this code the only report that renders and shows it the last record. Here is the current dev code. Anyone have a suggestion on solving the rendering and saving to pdft. Then attaching the file to an email? This is vb.net using current version of Stimulsoft.

Thanks
John W

Code: Select all

	Protected Sub StiWebViewer1_GetReport(ByVal sender As Object, ByVal e As StiReportDataEventArgs)
		Dim report = StiReport.CreateNewReport()
		Dim path = Server.MapPath("Reports/Report.mrt")
		report.Load(path)

		Dim dt As DataTable = report.Dictionary.GetDataSet("newLicenseRpt").Tables(0)

		'set variables
		Dim strEmail As String = ""
		Dim intApID As Integer = 0

		'For intCount As Integer = 1 To (dt.Rows.Count - 5)
		For Each dr As DataRow In dt.Rows

			If Not IsDBNull(dr.Item("email")) Then
				' gets eamil value if not dbNull
				strEmail = dr.Item("email").ToString
				'gets applicationID if it is different from the previous one. 
				If intApID <> dr.Item("applicationID") Then
					intApID = dr.Item("applicationID")
					'selects data based on applicationID
					report.Dictionary.Variables("varApplicationID").Value = intApID
					'creates report/makes .pdf  for each applicationID?
					e.Report = report

					'emails report under construction
					'emailReport(strEmail)
				End If
			End If
			'intCount += intCount
		Next

		'e.Report = report

	End Sub
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: Batch Email Part 2

Post by Lech Kulikowski »

Hello,

Should be something like the following:

Code: Select all

report.Load("e:\\sendemail.mrt");

foreach (DataRow row in emailsTable.Rows)
{
    report.Dictionary.Variables["Variable1"].Value = row["email"].ToString();

    report.Compile(false);
    report.Render(false);

    report.ExportDocument(StiExportFormat.Pdf, "e:\\" + row["email"].ToString() + ".pdf");

    // send email code
}
Thank you.
JohnW
Posts: 103
Joined: Mon Nov 20, 2017 8:29 pm

Disregard I have regData sorted.

Post by JohnW »

After too much trial and error I have this working.

I have pretty much everything sorted, the report iterated and convert to .pdf. So I am getting a report for each application number.

I am filering the data using the dataview.rowfilter process.
I pass the dataview to the report using report.regdata(dataview)

The last problem is the report is seeing all the data not just the filtered data from the dataview.

Am I using the regdata incorrectly?

Thanks
John W
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: Batch Email Part 2

Post by Lech Kulikowski »

Hello,

Do you use any filtrations in the report?

Thank you.
JohnW
Posts: 103
Joined: Mon Nov 20, 2017 8:29 pm

Re: Batch Email Part 2

Post by JohnW »

Lech:

I do have to deal data but I use a dataset as the vehicle. There is likely a far more elegant way to do this, but I have yet to find it. Essentially I am using this process
I built my report in the designer and made certain it is presenting what I wanted.
In code for the GetReport event I did the following:
- created a datatable and passed the data from the report.getdataset to it.
- I created a new dataset, dataadapter, connection, etc
- I then used the datatable as the means to iterated through the records.
- I was able to gain access to my pk and the email address this way.
- Using the pk I made a new select statement
- Using the adapter I was able to fill the dataset with specific data for that report. This is how I filtered down the records.
- Using report.regdata I was able to registed the new dataset for the report to use.
- Then the report is rendered, and saved to a .pdf file for the emailing process.

The upside is I deal with only the records needed and the iteration allows me to access data needed. Since there will only be a couple hundred of these reports run every day, the system as I have designed it should give good performance. At least It does on my 30 record test data set.

I ran into a multitude of problems. I had to learned how the report collects the data in the initial query, I learned report variables were not the solution for this, I needed to learn more about the report objects, how they fit into the process, and how to use them to my purpose. For the coding side I admit I struggled finding the documentation I needed. I am not saying its not there, but I had challenged finding it.

I do apppreciated the help I was given by you in getting this sorted out.

John W
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: Batch Email Part 2

Post by Lech Kulikowski »

Hello,

Yes, your implementation is the most optimal.

Also, please check the following samples:
https://www.stimulsoft.com/en/samples/r ... -from-code
https://www.stimulsoft.com/en/samples/r ... -from-code

Thank you.
Post Reply