In this example we will use the SendNotificationEx method to send a notification to an external email with an attached PDF on a workflow state change. To do this we will add code to the workflow State Actions

Example

  • Open M-Files Admin, then expand 'Connections to M-Files Servers\Local Computer\Document Vaults' 
  • Expand the desired vault and select 'Workflows' node 
  • Configure a simple workflow as shown below
  • Double-click the state on which you want to send the Notification (e.g. Listed for approval) 
  • In the 'State Properties' dialog, select the 'Actions' tab 
  • Check the 'Run Script' option, then click the 'Edit Code..' button
  • In the 'Edit VBScript code' window, add the following code


Sample VBScript

'create PentagonDOCS Notification object

Set ExDOCSNotification = GetExtensionObject("PentagonDOCS.Notifications")


'write details to the log

ExDOCSNotification.WriteLog ActivityID, "Send External Notification With PDF Attachments"


'create a list of external emails

Dim externalEmail : Set externalEmail = CreateObject("MFilesAPI.Strings")

externalEmail.Add -1,"exampleNotification@Pentagon.co.uk"


'get options Object and set our options

Dim options : Set options = ExDOCSNotification.GetNotitifcationsOptionsObject()

options.template = "default"

options.SendToExternalUsers = externalEmail

Options.AttachmentOptions.AttachFiles = True

Options.AttachmentOptions.AttachFilesFilter = "*"

Options.AttachmentOptions.AttachFilesIfExternal = True

Options.AttachmentOptions.AttachFilesIfMfilesUser = False


'send the notification

ExDOCSNotification.SendNotificationEx CurrentUserId.Value, objVer, options, ActivityID