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

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Email invoice as Excel and PDF separately in 1 plugin

Postby DannyC » Tue Jan 12, 2021 4:23 pm

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?
Last edited by DannyC on Tue Jan 12, 2021 4:48 pm, edited 1 time in total.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

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

Postby Scott.Pearce » Tue Jan 12, 2021 4:41 pm

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.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

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

Postby DannyC » Tue Jan 12, 2021 5:05 pm

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.
Attachments
Plugin Sales Orders Email after Processed Excel.xml
(53.43 KiB) Downloaded 468 times
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

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

Postby SBarnes » Sun Jan 17, 2021 5:15 pm

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.
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

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

Postby DannyC » Mon Jan 18, 2021 11:18 pm

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.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 3 guests