Page 1 of 1

Email invoice as Excel and PDF separately in 1 plugin

PostPosted: Tue Jan 12, 2021 4:23 pm
by DannyC
Using this as a guide viewtopic.php?f=26&t=1434
I am emailing debtors their invoice as an Excel file when processed.

Working a treat so thanks!
I also want to send the identical email a second time as a PDF, so I am just using
Code: Select all
      Email(salesOrderForm.SalesOrder, emailReportDialog.SelectedReport, emailReportDialog.NameToGiveAttachment, emailReportDialog.From, emailReportDialog.EmailTo, emailReportDialog.RequestReadReceipt, emailReportDialog.Subject, emailReportDialog.CC, emailReportDialog.BCC, emailReportDialog.Message, exportFormatTypeNew)
      Email(salesOrderForm.SalesOrder, emailReportDialog.SelectedReport, emailReportDialog.NameToGiveAttachment, emailReportDialog.From, emailReportDialog.EmailTo, emailReportDialog.RequestReadReceipt, emailReportDialog.Subject, emailReportDialog.CC, emailReportDialog.BCC, emailReportDialog.Message, exportFormatType)

in other words, calling the Email subroutine twice just with a different exportFormatType.

But I only get the Excel email. No PDF email comes through. Is there something I am missing?

Re: Email invoice as Excel and PDF separately in 1 plugin

PostPosted: Tue Jan 12, 2021 4:41 pm
by Scott.Pearce
I do not see a problem with what you have done there. Please attach the plugin and I will debug. Please ensure the plugin will work with a plain demo database.

Re: Email invoice as Excel and PDF separately in 1 plugin

PostPosted: Tue Jan 12, 2021 5:05 pm
by DannyC
Here's my plugin (edited to remove client identifying info)

It uses a List so only selected debtors who want to receive invoices as Excel get it.

I'm fairly sure it's something to do with saving the sales order between each email but have tried
salesOrder.Save()
without luck.

Re: Email invoice as Excel and PDF separately in 1 plugin

PostPosted: Sun Jan 17, 2021 5:15 pm
by SBarnes
If you change

Code: Select all
      Email(salesOrderForm.SalesOrder, emailReportDialog.SelectedReport, emailReportDialog.NameToGiveAttachment, emailReportDialog.From, emailReportDialog.EmailTo, emailReportDialog.RequestReadReceipt, emailReportDialog.Subject, emailReportDialog.CC, emailReportDialog.BCC, emailReportDialog.Message, exportFormatTypeNew)
      Email(salesOrderForm.SalesOrder, emailReportDialog.SelectedReport, emailReportDialog.NameToGiveAttachment, emailReportDialog.From, emailReportDialog.EmailTo, emailReportDialog.RequestReadReceipt, emailReportDialog.Subject, emailReportDialog.CC, emailReportDialog.BCC, emailReportDialog.Message, exportFormatType)


to

Code: Select all
      Email(salesOrderForm.SalesOrder, emailReportDialog.SelectedReport, emailReportDialog.NameToGiveAttachment, emailReportDialog.From, emailReportDialog.EmailTo, emailReportDialog.RequestReadReceipt, emailReportDialog.Subject, emailReportDialog.CC, emailReportDialog.BCC, emailReportDialog.Message, exportFormatTypeNew)
System.Diagnostics.Debugger.Launch
System.Diagnostics.Debugger.Break
      Email(salesOrderForm.SalesOrder, emailReportDialog.SelectedReport, emailReportDialog.NameToGiveAttachment, emailReportDialog.From, emailReportDialog.EmailTo, emailReportDialog.RequestReadReceipt, emailReportDialog.Subject, emailReportDialog.CC, emailReportDialog.BCC, emailReportDialog.Message, exportFormatType)


You will at least know if visual studio launches that it is getting to the second call, if not then I would suspect that somewhere possibly in another plugin a Jiwa Client Cancel exception is being thrown which halts Jiwa and there is nothing wrong with your code in this plugin and it will be an environmental side-effect which we have seen before and if memory serves correctly and if Mike can weigh in here as he was involved in the post about it I think one of the emailing plugins does exactly that.

At least by doing so you will know if the second call is being reached.

Re: Email invoice as Excel and PDF separately in 1 plugin  Topic is solved

PostPosted: Mon Jan 18, 2021 11:18 pm
by DannyC
So I was able to suss out the issue.

It would appear sending an invoice sets the SalesOrder.ChangeFlag or maybe SalesOrder.InsertFlag.
This forces it into
Code: Select all
   Public Sub Email(ByVal SalesOrder As JiwaSales.SalesOrder.SalesOrder, ByVal Report As JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport, ByVal NameToGiveAttachment As String, ByVal EmailFrom As String, ByVal EmailTo As String, ByVal RequestReadReceipt As Boolean, ByVal Subject As String, ByVal CC As String, ByVal BCC As String, ByVal Message As String, Optional ByVal ExportFormatType As CrystalDecisions.Shared.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Optional ReportFormulaTokenDictionary As Dictionary(Of String, Object) = Nothing)
      If SalesOrder.InsertFlag OrElse SalesOrder.ChangeFlag Then
         Throw New System.Exception("Cannot email a sales order until changes have been saved.")
      End If


so i simply did
Code: Select all
   Public Sub Email(ByVal SalesOrder As JiwaSales.SalesOrder.SalesOrder, ByVal Report As JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport, ByVal NameToGiveAttachment As String, ByVal EmailFrom As String, ByVal EmailTo As String, ByVal RequestReadReceipt As Boolean, ByVal Subject As String, ByVal CC As String, ByVal BCC As String, ByVal Message As String, Optional ByVal ExportFormatType As CrystalDecisions.Shared.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Optional ReportFormulaTokenDictionary As Dictionary(Of String, Object) = Nothing)
      If SalesOrder.InsertFlag OrElse SalesOrder.ChangeFlag Then
         'Throw New System.Exception("Cannot email a sales order until changes have been saved.")
         SalesOrder.Read(SalesOrder.InvoiceID)
      End If


It didn't like SalesOrder.Save(), so I did SalesOrder.Read instead. And it looks like its working now.