Batch emailing

Find general Jiwa support here.

Batch emailing

Postby robin » Wed May 20, 2009 11:50 am

Hi,

My Company has decided its high time to start using the batch emailing for invoices rather then printing each and every invoice.

The question has been brought up as to how you will know if an email has gone through.
I know you get the error in jiwa and so on, but essentially what I want to do is have the batch emails export into outlook (or similar) and email through that.

Is it possible?

This also applies to invoice emailing as our accounts dept emails through invoices from time to time but we have no way to know if the email has been sent or not.
(customer says didnt get email but no error came through jiwa and neither our outlook or our servers mail system shows the email has gone through)

pretty much I am unsure of how to set jiwa up to run through our local mail server.
robin
Occasional Contributor
Occasional Contributor
 
Posts: 26
Joined: Tue May 19, 2009 1:11 pm

Re: Batch emailing

Postby Scott.Pearce » Thu May 21, 2009 9:30 am

In the yet-to-be-released v6.5.13, a system setting has been introduced that you should find useful - "UseOutlookForEmail".

If this "UseOutlookForEmail" setting is turned on, then whenever the Jiwa email object is used (such as in the "Sample Report Emailing Script" scheduled script), it attempts to use outlook objects to send the email, instead of the internal Jiwa mail objects (therefore you need outlook installed on the client machine for this to work). The net effect of this is that emails sent will appear in your "Sent Items" folder in outlook if/when they are sent.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 742
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 221

Re: Batch emailing

Postby Mike.Sheen » Thu May 21, 2009 12:25 pm

As an alternative, you could also place an internal address on the TO or CC (or BCC) fields.

So, you would need to :

1. Have a mailbox called, say "[email protected]" setup in your mail system

2. Modify the Email Template in Jiwa (under the Batch Emailing configuration menu) to include your [email protected] as a BCC field.

3. Batch email as per normal, and your record of what was sent will be in the inbox of the [email protected] mailbox.
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: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: Batch emailing

Postby robin » Thu May 21, 2009 12:57 pm

Not quite what I need, as I can already see that in the email maint sections in Jiwa.

The big issue is there is no way to know if the email was rejected (i.e fat fingers spelling error)

I do like the first idea though, any idea of when we will be seeing .13?

In the meantime I think I will route my emails through a virtual SMTP server and create an account to send through with a rejection reply to my main email account.

Thanks for the prompt reply
Robin
robin
Occasional Contributor
Occasional Contributor
 
Posts: 26
Joined: Tue May 19, 2009 1:11 pm

Re: Batch emailing

Postby robin » Thu May 21, 2009 2:08 pm

Sometimes I love my job, sometimes I hate it.

In my continued pursuit of trying to get this system running they way they want it, I'v asked some questions and now they want to change again.

So what they want now, is "on the fly emailing" so basically when an invoice is processed, based on if the email field in account info is populated or not, either email the invoice and not print, or print the invoice.

possible...I would think yes, easy to do, I think not.

I am aware that I could turn printing on process off and then either hit email and if there is no email then print the invoice but apparently "that takes too many clicks" :roll:

Regards
Robin
robin
Occasional Contributor
Occasional Contributor
 
Posts: 26
Joined: Tue May 19, 2009 1:11 pm

Re: Batch emailing

Postby Mike.Sheen » Thu May 21, 2009 7:56 pm

robin wrote:So what they want now, is "on the fly emailing" so basically when an invoice is processed, based on if the email field in account info is populated or not, either email the invoice and not print, or print the invoice.

possible...I would think yes, easy to do, I think not.


Sure, that's possible - a little script in the process routine could do it.

I'll post the breakout here, if you provide me with answers to the following 4 questions :

1. If multiple invoice formats are defined, which one is to be emailed ? Or do you want them all emailed ?

2. If the email address is blank (that's the email address on the "Email Address" field of the Debtor tab on the sales order form), do you want it to behave as per normal - ie : just print ?

3. Is this only from the batch process form ? Or are they typically processing single orders ? If it's single orders, initiated from the sales order entry form, then we could make it a bit neater by adding a menu option to process + email or print - rather than loading the process invoice dialog.

4. What version of Jiwa is this to be for ?
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: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: Batch emailing

Postby robin » Fri May 29, 2009 11:41 am

1. If multiple invoice formats are defined, which one is to be emailed ? Or do you want them all emailed ?


Just the invoice, we run Three invoice types, Office Copy, Picking Slip and Invoice.

2. If the email address is blank (that's the email address on the "Email Address" field of the Debtor tab on the sales order form), do you want it to behave as per normal - ie : just print ?


Yes, if there is no email address, just print the Invoice as per normal.

3. Is this only from the batch process form ? Or are they typically processing single orders ? If it's single orders, initiated from the sales order entry form, then we could make it a bit neater by adding a menu option to process + email or print - rather than loading the process invoice dialog.


We do not use any batch processing at the moment, so every order is processed on it's own

4. What version of Jiwa is this to be for ?


Application Version : 6.5.11
Database Version : 6.5.11


Thank you so much for this, I started work on a breakout this morning which was to not allow processing unless the invoice was emailed, however this will work much better.

Regards
Robin
robin
Occasional Contributor
Occasional Contributor
 
Posts: 26
Joined: Tue May 19, 2009 1:11 pm

Re: Batch emailing

Postby Mike.Sheen » Fri May 29, 2009 5:27 pm

Robin,

Ok, here it is.

Once you've followed the instructions below, the sales order form will have a new menu option under the record menu : "Process and Email or Print".

When selected, the current sales order is processed, and then either emailed or printed, depending on the value of the debtor email address (if blank print, if not blank, then email).

The report and printer to use is drawn from the printer setup as defined in the sales order form. The first invoice type report configured is what is printed. It will print the number of copies configured to print (if printing), but if emailing only attaches the invoice once.

The subject and body will need to be customised - i've just put a rather simple example in there.

There are 3 code fragments to paste into the breakout scripts for sales order entry. I advise you to work on a copy of your live data first.

There is one thing you will have to change - the sending address needs to be configured. Find the line which reads
Code: Select all
From = "[email protected]"

and replace it with an appropriate address.


1. Add this code to the very start of the Form Custom Menu Clicked breakout of the sales order form, before any existing code.

Code: Select all
If MenuIndex = 4 Then
      ProcessAndEmailOrPrintInvoice SalesOrderObject, FormObject, MDIParentObject
   End If


2. Add this code to the very start of the Form Loaded breakout of the sales order entry form (before any other existing code)

Code: Select all
   FormObject.mRecordCustom(4).Caption = "Process and Email or Print"
   FormObject.mRecordCustom(4).Visible = True
   FormObject.mRecordCustom(4).Checked = False


3. Add this code to the Form Loaded breakout of the sales order entry form (copy the code below AFTER the End Sub of the existing breakout code)

Code: Select all
Public Function ProcessSalesOrder(FormObject, SalesOrderObject)
Dim SOProcObject
Dim lErrorString
Dim lErrorModule
   
    ProcessSalesOrder = True
   
    If ProcessSalesOrder = True Then
        Set SOProcObject = CreateObject("JiwaProcessSO.clsSalesOrderProcess")
        Set SOProcObject.Database = SalesOrderObject.Database
        Set SOProcObject.CommonLib = SalesOrderObject.JiwaCommLib
        Set SOProcObject.JLib = SalesOrderObject.JLib
        Set SOProcObject.MDIParent = FormObject.MDIParent
        Set SOProcObject.SystemProfile = SalesOrderObject.SystemProfile
    End If
   
    If ProcessSalesOrder = True Then
        If SOProcObject.Setup = 0 Then
            ProcessSalesOrder = False
            lErrorString = SOProcObject.ErrorString
            lErrorModule = SOProcObject.ErrorModule
        End If
    End If
   
    If ProcessSalesOrder = True Then
        If SOProcObject.ProcessSalesOrder(SalesOrderObject.InvoiceID) = 0 Then
            ProcessSalesOrder = False
            lErrorString = SOProcObject.ErrorString
            lErrorModule = SOProcObject.ErrorModule
        End If
    End If
           
    If Not (SOProcObject Is Nothing) Then
        SOProcObject.CleanUp
        Set SOProcObject = Nothing
    End If
   
    If ProcessSalesOrder = False Then
        MsgBox "Error occurred whilst processing : " & lErrorString & vbCrLf & "Module : " & lErrorModule
    End If
       
End Function

Public Function EmailReportDirect(MDIParentObject, SalesOrderObject, ReportFileName, From, EmailTo, Subject, CC, BCC, Message, NameToGiveAttachment, EM_Main_RecID, SourceID, SourceType, SourceDisplayNo, SourceDrillDownIndex, rtnErrorModule, rtnErrorString)

Dim PrintReportObject
Dim m_JiwaReportRange
Dim MyLoop
Dim OldCriticalSectionFlag

    EmailReportDirect = True
    EM_Main_RecID = ""
   
    If EmailReportDirect = True Then
      InternetMailControlLicenseKey = "IPELLICSJMMBMVTC"
      Set InternetMailControl = CreateObject("SocketTools.InternetMail")   
      ' Initialize the control with the license key
      nError = InternetMailControl.Initialize(InternetMailControlLicenseKey)
      If nError > 0 Then
         rtnErrorModule = "InternetMailControl.Initialize"
         rtnErrorString = "Unable to initialize control:" & vbCrLf & InternetMailControl.LastErrorString
         EmailReportDirect = False
      End If     
   End If
      
    If EmailReportDirect = True Then
       Set PrintReportObject = CreateObject("JiwaPrintReport.clsJiwaPrintReport")
       Set PrintReportObject.Database = SalesOrderObject.Database
       Set PrintReportObject.JiwaCommLib = SalesOrderObject.JiwaCommLib
       Set PrintReportObject.JLib = SalesOrderObject.JLib
       Set PrintReportObject.CrystalApplicationObject = MDIParentObject.GetJWPrintObject
       Set PrintReportObject.SystemProfile = SalesOrderObject.SystemProfile
       Set PrintReportObject.InternetMailControl = InternetMailControl
   End If
   
    If EmailReportDirect = True Then
       PrintReportObject.ClearError
       PrintReportObject.SetUp
    End If
   
    If EmailReportDirect = True Then       
       If PrintReportObject.ErrorString <> "" Then
           rtnErrorString = PrintReportObject.ErrorString
           rtnErrorModule = PrintReportObject.ErrorModule
           EmailReportDirect = False
        End If
    End If
   
    If EmailReportDirect = True Then 
        If PrintReportObject.LoadReport(ReportFileName) = 0 Then
            rtnErrorString = PrintReportObject.ErrorString
           rtnErrorModule = PrintReportObject.ErrorModule
            EmailReportDirect = False
      End If
   End If
   
   If EmailReportDirect = True Then             
      'PrintReportObject.OverrideRecordSelectionCriteria = RecordSelectionFormula
                 
        For Each m_JiwaReportRange In PrintReportObject.JiwaPrintReportRanges
           Select Case UCase(Trim(PrintReportObject.JiwaPrintFormulas(m_JiwaReportRange.FormulaKey).Name))
              Case UCase("{@Pass_CurrentHistNo}")
                 m_JiwaReportRange.Value = SalesOrderObject.Database.FormatNumber(Format(SalesOrderObject.SelectedHistoryNo, "00"))
              Case UCase("{@Pass_InvoiceNo}")
                 m_JiwaReportRange.Value = SalesOrderObject.InvoiceNo
              Case UCase("{@Pass_SP_InvoiceHistoryID}")
                 m_JiwaReportRange.Value = SalesOrderObject.SalesOrderHistorys(SalesOrderObject.SelectedHistoryNo).InvoiceHistoryID
           End Select
        Next
   End If
   
   If EmailReportDirect = True Then 
        If PrintReportObject.UpdateReport = 0 Then
            rtnErrorString = PrintReportObject.ErrorString
            rtnErrorModule = PrintReportObject.ErrorModule
              EmailReportDirect = False
      End If
   End If
   
   If EmailReportDirect = True Then 
      If PrintReportObject.EmailReport(From, EmailTo, Subject, CC, BCC, Message, NameToGiveAttachment, EM_Main_RecID, False, SourceID, SourceType, SourceDisplayNo, SourceDrillDownIndex) = 0 Then
            rtnErrorString = PrintReportObject.ErrorString
            rtnErrorModule = PrintReportObject.ErrorModule
              EmailReportDirect = False
      End If
    End If   
   
    If Not (PrintReportObject Is Nothing) Then
       PrintReportObject.CleanUp
       Set PrintReportObject = Nothing
    End If
       
End Function

Public Function GetReportDetails(SalesOrderObject, rtnReportFileName, rtnReportDescription, rtnLogicalPrinterDeviceName, rtnLogicalPrinterDriverName, rtnLogicalPrinterPort, rtnNumberCopies, rtnErrorString, rtnErrorModule)
   GetReportDetails = True

   Set PrintSetupObject = CreateObject("JiwaSOPrintSetup.clsSalesOrderReports")   
   Set PrintSetupObject.SystemProfile = SalesOrderObject.SystemProfile
   
   If PrintSetupObject.ReadRecords = False Then
      rtnErrorString = PrintSetupObject.ErrorString
      rtnErrorModule = PrintSetupObject.ErrorModule
      GetReportDetails = False
   Else
      For Each lReport In PrintSetupObject
         If lReport.ReportType = 0 Then
            rtnReportFileName = lReport.ReportPath & "\" & lReport.ReportFileName
            rtnReportDescription = lReport.ReportDescription
            
            Set LogicalPrinter = SalesOrderObject.SystemProfile.LogicalPrinters.GetLogicalPrinterFromName(lReport.Printer)
            
            rtnLogicalPrinterDeviceName = LogicalPrinter.DeviceName
            rtnLogicalPrinterDriverName = LogicalPrinter.DriverName
            rtnLogicalPrinterPort = LogicalPrinter.Port
            
            rtnNumberCopies = lReport.NumberOfCopies
            Exit For
         End If
      Next
   End If
   
End Function

Public Sub ProcessAndEmailOrPrintInvoice(SalesOrderObject, FormObject, MDIParentObject)      
   NumberCopies = 1
   
   If GetReportDetails(SalesOrderObject, ReportFileName, ReportDescription, LogicalPrinterDeviceName, LogicalPrinterDriverName, LogicalPrinterPort, NumberCopies, ErrorString, ErrorModule) = 0 Then
      MsgBox ErrorString
   Else         
      If Trim(ReportFileName) = "" Then
         MsgBox "No report has been defined."
      Else
         If ProcessSalesOrder(FormObject, SalesOrderObject) = True Then   
         
            FormObject.ReadRecord 0      
            
            If Trim(SalesOrderObject.SalesOrderHistorys(SalesOrderObject.SelectedHistoryNo).EmailAddress) <> "" Then
               
               From = "[email protected]"
               
               EmailTo = SalesOrderObject.SalesOrderHistorys(SalesOrderObject.SelectedHistoryNo).EmailAddress
               Subject = "Invoice " & SalesOrderObject.InvoiceNo
               CC = ""
               BCC = ""
               Message = "Dear " & SalesOrderObject.DebtorContactName & "," & vbrclf & vbcrlf & "Please find attached your invoice."
               NameToGiveAttachment = SalesOrderObject.InvoiceNo & ".pdf"
               SourceID = SalesOrderObject.InvoiceID
               SourceType = "Sales Order"
               SourceDisplayNo = SalesOrderObject.InvoiceNo
            
               If EmailReportDirect(MDIParentObject, SalesOrderObject, ReportFileName, From, EmailTo, Subject, CC, BCC, Message, NameToGiveAttachment, EM_Main_RecID, SourceID, SourceType, SourceDisplayNo, 3, ErrorModule, ErrorString) = 0 Then
                  MsgBox ErrorString
               End If
               
               SalesOrderObject.AddEmailLog Subject, EmailTo, From, CC, BCC, NameToGiveAttachment, "", Message, EM_Main_RecID, False, 0
               
                  If SalesOrderObject.SaveOrder(, True) = 0 Then
                     MsgBox SalesOrderObject.ErrorString
                  End If
              Else
               MDIParentObject.ResetReportSelectionFormulaTokens
               MDIParentObject.AddReportSelectionFormulaToken "{@Pass_CurrentHistNo}", SalesOrderObject.SelectedHistoryNo
               MDIParentObject.AddReportSelectionFormulaToken "{@Pass_InvoiceNo}", SalesOrderObject.InvoiceNo
               MDIParentObject.AddReportSelectionFormulaToken "{@Pass_SP_InvoiceHistoryID}", SalesOrderObject.SalesOrderHistorys(SalesOrderObject.SelectedHistoryNo).InvoiceHistoryID
               MDIParentObject.PrintReportDirect ReportFileName, LogicalPrinterDeviceName, LogicalPrinterDriverName, LogicalPrinterPort, NumberCopies, False, ""
               
               SalesOrderObject.AddPrintLog SalesOrderObject.SalesOrderHistorys(SalesOrderObject.SelectedHistoryNo).Ref & " - " & ReportDescription & " (Printed By " & SalesOrderObject.Database.JiwaLoginUserName & ")", 0
               
                   If SalesOrderObject.SaveOrder(, True) = 0 Then
                      MsgBox SalesOrderObject.ErrorString
                   End If
              End If              
            
               FormObject.ReadRecord 0
           End If
      End If
   End If
End Sub
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: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: Batch emailing

Postby robin » Fri May 29, 2009 6:38 pm

wow thats a lot more script then i imagined i would need to write when i started out on this myself...


almost working....just one small error on line 114

when i hit the button it process but after a couple of seconds i get an error pop up:

Type Mismatch: 'Format' at line 114.

In my form loaded breakout line 114 is:

Code: Select all
Case UCase("{@Pass_InvoiceNo}")


I can't see any fault with that code...then again it is 5pm haha

Thank you so much for do this for me, its highly appreciated.

Regards
Robin
robin
Occasional Contributor
Occasional Contributor
 
Posts: 26
Joined: Tue May 19, 2009 1:11 pm

Re: Batch emailing

Postby Mike.Sheen » Fri May 29, 2009 9:11 pm

robin wrote:almost working....just one small error on line 114

when i hit the button it process but after a couple of seconds i get an error pop up:

Type Mismatch: 'Format' at line 114.

In my form loaded breakout line 114 is:

Code: Select all
Case UCase("{@Pass_InvoiceNo}")


I can't see any fault with that code...then again it is 5pm haha


Ok, then try replacing
Code: Select all
 m_JiwaReportRange.Value = SalesOrderObject.Database.FormatNumber(Format(SalesOrderObject.SelectedHistoryNo, "00"))


With
Code: Select all
 m_JiwaReportRange.Value = SalesOrderObject.SelectedHistoryNo


That seemed to work for me as well (I think different versions of VB script runtime deployed may behave differently - ie; Vista vs XP / 2003 / 2008).
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: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Next

Return to Core Product Support

Who is online

Users browsing this forum: No registered users and 0 guests

cron