Sales Order printed, then email  Topic is solved

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

Sales Order printed, then email

Postby DannyC » Mon Aug 17, 2015 2:22 pm

I want to do an email after a delivery docket has been printed.
I am exploiting some code in the "Sales Order Custom Email" plugin you've written - basically I want to fire the
Code: Select all
Private Sub EmailSalesOrder
from the printed event.
I need to pass the SalesOrderForm object into the Private Sub EmailSalesOrder but I can't work out how to do it.

So far I have
Code: Select all
    Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
      Dim salesOrderForm As JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm = DirectCast(JiwaForm, JiwaSalesUI.SalesOrder.SalesOrderEntryForm)
      AddHandler salesOrderForm.SalesOrder.Printed, AddressOf SOPrinted
   End Sub

   Public Sub SOPrinted (sender As Object, e As System.eventargs, ByVal Report As JiwaApplication.PrintGroup.SalesOrderReports.SalesOrderReport)
        If Report.Name = "Delivery Docket" Then
'         msgbox ("You have printed the delivery docket")
         Dim salesOrderForm As JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(sender, JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
         EmailOrderConfirmation(salesOrderForm)
         Throw New JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ClientCancelledException
      End If
   End Sub
'''''''''''''      
   Private Sub EmailOrderConfirmation(ByVal SalesOrderForm As JiwaSalesUI.SalesOrder.SalesOrderEntryForm,  Optional ByVal ExportFormatType As CrystalDecisions.Shared.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)      
        If salesOrderForm.SalesOrder.ChangeFlag Or salesOrderForm.SalesOrder.InsertFlag Then
            Throw New System.Exception("Cannot email a sales order until the changes have been saved.")
        End If
   '''This is the same as the Jiwa code
   End Sub

but I clearly have a mix up between the object types. It seems the sender in the SOPrinted sub is not a form so it can't cast to a form type.

When I print, I get an error
unable to cast object of type JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder to type JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm.
How can I get the SalesOrderForm object to pass into the EmailSalesOrder sub?

Thanks

Danny
User avatar
DannyC
Senpai
Senpai
 
Posts: 718
Joined: Fri Mar 22, 2013 12:23 pm
Topics Solved: 31

Re: Sales Order printed, then email  Topic is solved

Postby Scott.Pearce » Tue Aug 18, 2015 3:44 pm

If you look at the type of the sender object passed to SOPrinted, you will see that it is in fact of type JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder (and I believe you did figure this). So, begin by casting that to an appropriately typed variable, thus:

Code: Select all
Dim salesOrderObejct As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaFinancials.Jiwa.JiwaSales.SalesOrder.SalesOrder)


Now, there is a really useful property called "Client" in many of our business logic objects from which you can get to the form!

Code: Select all
Dim salesOrderForm As JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.SalesOrderEntryForm = DirectCast(salesOrderObejct.client, JiwaFinancials.Jiwa.JiwaSalesUI.SalesOrder.BaseSalesOrderEntryForm)
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


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 1 guest