Skip to content
Back to Blog

Trigger an Email when a specific action is done in Visual

Contractor3 min read
  • Macros
  • Email Automation
  • Visual ERP
  • Workflow

Let's use a Macro to automate some emails that can make our life so much easier.

Below is Macro that will send an email out to a group or an individual when a certain task is performed. In my case, whenever an Engineering Master is created in Visual's "Manufacturing Window", it will send an Email notification.

Change the below highlighted fields and save the code.

Dim Pid
Dim eng
Dim ans

If WO_TYPE = "M" Then
    Pid = InputBox("Enter the Part ID for the new EM", "Part ID")
    Part_ID = Pid
    ENGINEERED_BY = USER

    Set NewMail = CreateObject("CDO.Message")
    Set mailConfig = CreateObject("CDO.Configuration")

    ' load all default configurations
    mailConfig.Load -1
    Set fields = mailConfig.fields

    'Set All Email Properties
    With NewMail
        .Subject = "Your Trigger subject " & pid & " ?"
        .From = "email@gmail.com"
        .To = "YOUR_GROUP_OF_EMAILS_HERE"
        .CC = ""
        .BCC = ""
        .textbody = "Your trigger email message"
    End With

    msConfigURL = "http://schemas.microsoft.com/cdo/configuration"

    With fields
        'Enable SSL Authentication
        .Item(msConfigURL & "/smtpusessl") = True

        'Make SMTP authentication Enabled=true (1)
        .Item(msConfigURL & "/smtpauthenticate") = 1

        'Set the SMTP server and port Details
        'To get these details you can get on Settings Page of your Gmail Account
        .Item(msConfigURL & "/smtpserver") = "smtp.gmail.com"
        .Item(msConfigURL & "/smtpserverport") = 465
        .Item(msConfigURL & "/sendusing") = 2

        'Set your credentials of your Gmail Account
        .Item(msConfigURL & "/sendusername") = "YOUR_EMAIL_ADDRESS@GMAIL.COM"
        .Item(msConfigURL & "/sendpassword") = "YOUR_PASSWORD"

        'Update the configuration fields
        .Update
    End With
    
    NewMail.Configuration = mailConfig
    NewMail.Send
End If

Tip

You can name your Macro whatever you wish to but Visual has a flexibility to call a few Macros based on certain events.

Visual's "OnEvent" Macros

  • OnSave: This will be called right after hit save. This is before the data hits the database.
  • OnAfterSave: This is a little different from OnSave. This is run after the data hits the database.
  • OnLoad: This fires after the data is loaded in the window.
  • OnNew: This fires right after "New" button is clicked.

However, manufacturing window has some new Macros:

  • OnAfterSaveWO
  • OnAfterSaveOP
  • OnAfterSaveMAT
  • OnAfterSaveLEG
  • OnNewWO
  • OnNewOP
  • OnNewMAT
  • OnNewLEG
  • OnLoadWO
  • OnLoadOP
  • OnLoadMAT
  • OnLoadLEG

Applications

  • Sending automatic Emails to your customer whenever a Sales Order is created for them.
  • Sending Emails to Employees when they are setup in Visual under employee maintenance. (Same with a new customer added).
  • Sending Emails when a Picklist is generated.

Well, the applications are infinite here.

Need help with your Infor Visual system? Get in touch.