Description

This documents explains how the WMS can execute USER DEFINED PROGRAMS or scripts written in Visual Basic and reference/defined in the system Preferences.XML configuration file.

Datapel WMS provides OPEN INTEGRATION points for system designers allowing information within the workspace to be shared with other business applications or to have custom program scripts executed at various points during WORKFLOW EXECUTION to actively push/pull information to and from the WMS service engine.

Examples include:

  • Website Integration
  • Workflow Automation/Tracking
  • Production Systems / Stock Control devices

Detail Steps

Creating a Script:

1. A script must be loaded into the Prefs.XML configuration file - WMS must be restarted to apply changes made. There are a number of paths which can be configured allowing you to customise the WMS.

2. The Scripts path within the XML file is shown below:


A Script is constructed as follows:

  
     WMS_OnStartup
     True
     HelloWorld.vbs
  
  
     WO_OnUpdate_WorkOrder
     False
     SUB WO_ONUPDATE_WORKORDER(); msgbox "WO_OnUpdate_WorkOrder"; END SUB
  

3. The first script example references a SCRIPT FILE which MUST BE LOCATED in the app.path\SCRIPTS folder. In this example the script file contains the following code:

  Sub WMS_ONSTARTUP() 
     MsgBox "    ----- Welcome WMS User -----     "
  End Sub

4. The second script example contains INLINE code and must ALWAYS be contained on a single line - line breaks are created by WMS whenever a semi-colon is found. INLINE code is only recommend for small scripts.

5. WMS will pass initialised objects to your script code - an example is shown below. As a minimum the Connection Object will always be available.

  Sub SO_AFTERCREATE_SALEORDER()
  ' Passed as Global References by WMS
  ' "Connection", modMain.Connection
  ' "User", gobjUserLogin
  ' "Preferences", gobjPreferences
  ' "ItemList", gobjBaseStockColl
  ' "CardList", gobjCardsColl
  ' "Locations", gobjLocationsColl
  ' Passed as Local References within SALES context
  ' "SaleOrder", objSale
  ' "BillCard", objCard
  ' "ShipCard", objShipCard
  ' "BillAddr", objCardAddr
  ' "ShipAddr", objShipAddr
  Dim objOutlook 
  Dim objOutlookMsg 
  Dim objSaleLine
  Dim objBaseStock
  Dim sOrder
  Dim sNotes
  Dim bComplete
  'On Error Resume Next
  If InStr(1,UCase(SaleOrder.Comment),"EMAIL") > 0 Or InStr(1,ShipCard.Identifiers,"E") > 0 Then
   sOrder = "This is an Automated Confirmation Email of your recently placed order..." + Chr(13) + Chr(10)
   sOrder = sOrder + "-----------------------" + Chr(13) + Chr(10)
   sOrder = sOrder + "Invoice  # " + CStr(SaleOrder.InvoiceNumber) + Chr(13) + Chr(10)
   sOrder = sOrder + "Your Ref # " + CStr(SaleOrder.PurchaseOrder) + Chr(13) + Chr(10)
   sOrder = sOrder + "Email to  " + CStr(ShipAddr.Email) + Chr(13) + Chr(10)
   sOrder = sOrder + "-----------------------" + Chr(13) + Chr(10)
   sOrder = sOrder + Chr(13) + Chr(10)
   
   ' Create Body of Email
   For Each objSaleLine In SaleOrder.SalesLines
       Set objBaseStock = ItemList.Item("K" & CStr(objSaleLine.BaseStockID))
    sOrder = sOrder + "  " + CStr(objSaleLine.Quantity) + chr(9) + "   x    " + objBaseStock.ItemName + Chr(13) +         Chr(10)
   Next
   
   sOrder = sOrder + "-----------------------" + Chr(13) + Chr(10)
   sOrder = sOrder + "Please contact us immediately if you would like to change your order." + Chr(13) + Chr(10)
   sOrder = sOrder + Chr(13) + Chr(10)
   sOrder = sOrder + Chr(13) + Chr(10)
   sOrder = sOrder + "We appreciate your business - Datapel Sales." + Chr(13) + Chr(10)
   sOrder = sOrder + "sales@datapel.com" + Chr(13) + Chr(10)
   
   Set objOutlook = CreateObject("Outlook.Application")
   
   If Not objOutlook Is Nothing Then
       Set objOutlookMsg = objOutlook.CreateItem(0)
       With objOutlookMsg
          .To = "adam.wesley@datapel.com"
          .Cc = "sales@datapel.com"
          .Subject = "Datapel Order Confirmation #" +  CStr(SaleOrder.InvoiceNumber) 
          .Body = sOrder
          .Display
       End With
   Else
       MsgBox "Action Failed: Unable to open Outlook...             ", vbOKOnly, "Email..."
   End If
   
   ' Update the Sale Order Notes to indicate Order was emailed
   sNotes = FormatDateTime(Now()) + " (System Action): Sent Order Confirmation Email to " + CStr(ShipAddr.Email)
      ' Populate data from SAL_Sales table
      Dim objSalesColl
      
      Set objSalesColl = CreateObject("DTAdvancedInventory.CSalesColl")
      Set objSalesColl.DataConnection = Connection
      
      bComplete = objSalesColl.Populate("WHERE SAL_ID = " & CStr(SaleOrder.SalesID))
      If bComplete Then
       objSalesColl.Item(1).Notes = sNotes
       bComplete = objSalesColl.SaveData(False)
   End if 
  End If
  End Sub

Related Information

Scripts are executed INLINE with your WMS process - therefore a SCRIPT that halts processing will stop execution of the WMS - this is not recommended.