Skip to main content

Workflow update notification

Description​

Inform a user per e-mail about every creation and update of any workflow. A special template with audit information should be used to show the changed values.

Approach​

A HTML mail template and audit data is used.

Prerequisites

Define the recipients e-mail address in the Environment variables tab, and create a HTML template in the Templates tab.

  • $DEMO_RECIPIENT - the E-Mail address of the user of the demo instance
  • workflow-watch-all-notes - the name of the template

Default values are used to solve the following problems:

  • Different environments: E.g. template id's are different in sandbox and production. Testing is done in sandbox - after completion the package code can be transferred to production without a change, only the default values must be changed in production.
  • Different packages: The same value should be used in different packages - a default value is identical in every package of an environment.

Templates are used so solve the following problems:

  • Special text for mail or notes maintained outside the package code
  • Identify the template by simple template names to use exactly the one that is needed
  • Different language versions and fallback language versions of the same template are supported

In addition the webhook must be set with following parameters:

  • Account: datacenter
  • Event: workflow.create, workflow.update

Commented code​

//
// send an email on every Change update
//

// write a log entry
log('******* Send Change Notification Begin ********');

// merge audit data from the latest update into the $workflow variable
mergeAudit(workflow); // inject workflow with latest audit information

// 'workflow-watch-all-notes' is defined in 'Templates', uses $workflow
// Use the Template 'workflow-watch-all-notes' to create a HTML Mail
// and save the result in the variable $mailData
// A different language can be used by adding a langugae parameter ('de', ...)
// without a parameter the default language is used
let mailData = createTemplateHTMLMail('workflow-watch-all-notes');

// Set the mail TO at the value that is storen in the default variable $DEMO_RECIPIENT
mailData.to = $DEMO_RECIPIENT; // defined in 'Defaults'

// Set the mail-out profile that is used to send the mail
// Since 'built-in' is set as the default mail-out profile this line is not needed,
// but it shows how to use different mail out profiles
mailData.profile = 'built-in'; // defined in 'Email Out' (optional)

// send the mail
sendMail(mailData);

// write a log entry that the end of the package execution is reached
log('******* Send Change Notification End ********');

The template that is used in this example is explained on the Templates page.

Condensed code​

The comments and log entries are helpful, but make the code above quite long. Leaving them out, the code can be condensed to:

mergeAudit(workflow);
let mailData = createTemplateHTMLMail('workflow-watch-all-notes');
mailData.to = $DEMO_RECIPIENT;
sendMail(mailData);