Jiwa 8 sales order emailing when processing

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

Jiwa 8 sales order emailing when processing

Postby DannyC » Tue Nov 11, 2025 3:03 pm

In J7, I have a plugin which automatically emails after processing.

Originally developed for earlier versions of Jiwa 7 it's been tweaked for 7.2.1 and working well.
See an example here
viewtopic.php?f=26&t=1553

When compiling under Jiwa 8, I'm getting a error on
Code: Select all
Dim emailReportDialog As JiwaSalesUI.SalesOrder.EmailReport = candidate.Manager.DialogFactory.CreateDialog(Of JiwaSalesUI.SalesOrder.EmailReport)(New Object() {candidateReportsToEmail}, _salesOrderForm, "Sales Order Entry")


I can see EmailReport doesn't exist any more which is likely because the email dialog is completely different in v8. So yeah, understandable.
What would be the recommended alternative?

I'm figuring just using SalesOrder.Email as long as we have the SalesOrderReport, attachment name, From, To, subject, body et al.
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Jiwa 8 sales order emailing when processing

Postby Mike.Sheen » Wed Nov 12, 2025 8:43 am

If it's a dialog with preview functionality you want, then here's what the sales order form does when you press the email tool on the ribbon:

Code: Select all
Public Sub EmailSalesOrder(Optional ByVal ExportFormatType As JiwaApplication.JiwaReportProvider.ExportFormats = JiwaApplication.JiwaReportProvider.ExportFormats.PortableDocFormat)
    If SalesOrder.ChangeFlag Or SalesOrder.InsertFlag Then
        Throw New Exception("Cannot email a sales order until the changes have been saved.")
    End If

    If GetAbstractPermission("sales order - email invoices") <> JiwaApplication.Security.UserGroup.AccessLevels.Allow Then
        Throw New Exception("You do not have sufficient privileges to email an invoice.")
    End If

    If SalesOrder.SalesOrderReports.Count = 0 Then
        If MsgBox("No sales order reports have been defined." & System.Environment.NewLine & System.Environment.NewLine & "Would you like to set some up now ?", vbYesNo, "No Sales Order Reports Configured") = vbYes Then
            PrinterSetup()
        End If
        Exit Sub
    End If

    Dim candidateReports As JiwaApplication.JiwaCollection(Of JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport) = SalesOrder.GetCandidateReportsToPrint()

    Dim emailPreviewDialog As JiwaApplication.JiwaEmailUI.EmailPreviewDialog = Manager.DialogFactory.CreateDialog(Of JiwaApplication.JiwaEmailUI.EmailPreviewDialog)(New Object() {JiwaApplication.JiwaEmailUI.EmailPreviewDialog.OperationModes.Preview, Me.SalesOrder}, Me, IIf(SalesOrder.CreditNote, "Credit Note", "Sales Order Entry"))
    emailPreviewDialog.ReportUltraComboEditor.Items.Add(Nothing, "No Report")
    emailPreviewDialog.ReportUltraComboEditor.SelectedIndex = 0

    Dim previousEmailReportID As String = Nothing
    Manager.GetProfileKey(Manager.Database.JiwaLoginUserID, FindForm.GetType.ToString, "EmailReportID", previousEmailReportID)

    For Each salesOrderReport As JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport In candidateReports
        emailPreviewDialog.ReportUltraComboEditor.Items.Add(salesOrderReport.ReportDefinition.Report, String.Format("{0} - ({1} | {2})", salesOrderReport.Name, salesOrderReport.ReportDefinition.Report.Title, salesOrderReport.ReportDefinition.Report.FileName))
        If previousEmailReportID = salesOrderReport.ReportDefinition.Report.RecID Then
            emailPreviewDialog.ReportUltraComboEditor.SelectedItem = emailPreviewDialog.ReportUltraComboEditor.Items(emailPreviewDialog.ReportUltraComboEditor.Items.Count - 1)
        End If
    Next

    If emailPreviewDialog.ShowDialog(Me) = Windows.Forms.DialogResult.OK Then
        ' Save selected report
        If emailPreviewDialog.ReportUltraComboEditor.SelectedItem IsNot Nothing AndAlso emailPreviewDialog.ReportUltraComboEditor.SelectedItem.DataValue IsNot Nothing Then
            Manager.SetProfileKey(Manager.Database.JiwaLoginUserID, FindForm.GetType.ToString, "EmailReportID", emailPreviewDialog.ReportUltraComboEditor.SelectedItem.DataValue.RecID)
        Else
            Manager.SetProfileKey(Manager.Database.JiwaLoginUserID, FindForm.GetType.ToString, "EmailReportID", Nothing)
        End If

        Dim oldCursor As System.Windows.Forms.Cursor = Cursor
        Try
            Cursor = System.Windows.Forms.Cursors.WaitCursor
            SalesOrder.Email(DirectCast(emailPreviewDialog.ReportUltraComboEditor.SelectedItem.DataValue, JiwaApplication.Report.Configuration.Report), emailPreviewDialog.EmailMessage, ReportFormulas, ReportReplacementTokens, ExportFormatType)
        Finally
            Cursor = oldCursor
        End Try
    End If

End Sub


You should be able to adapt that to suit your needs.

If you want to email without a UI, then you should just use SalesOrder.Email - which the above code does right at the end, after collecting all it needs from the dialog.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 0 guests