Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Sending Event Based Email Notifications in Silk Performer

Sending Event Based Email Notifications in Silk Performer

In this example:

  • An event handler is defined to handle specific errors and if a condition is met an email is sent with details of the error.
  • Project attributes are used to store the email function parameters such as SMTP server, recipient, sender etc.  This makes changing these settings very easy.
  • HTML files are added to the data files section and account for most of the HTML-formatted email. Using HTML files allows for easy customization of the email look and feel in an external HTML editor rather than coding the entire HTML body in the function itself which would be messy.
  • The body of the HTML message contains placeholders that are replaced by dynamic values about the error at runtime. Defining these placeholders in the HTML makes it easy to find and replace them using string replace functions.
  • An include file (.bdh) is used to define a function used by the event handler to compose and send the email.
  • The email functionality resides in a DLL generated in Visual studio which leverages the .NET Framework System.Net.Mail namespace.  This DLL receives the email parameters specified in the attributes and also the error details generated at runtime, sends the email message and returns a string about the status of that operation.

To use the script, first configure the email parameters. From the Workbench, go to PROJECT | PROJECT ATTRIBUTES, and enter the information suitable to your environment.

The script raises the error ‘BrowserEngine: 32’ by requesting a url which will return 404 file not found. The event handler captures any error and the time it occurs and calls the custom SendMail() function defined in the include file ‘email.bdh’. This is the event handler code:

The SendMail() function receives the last error and the time the error occurred as input parameters. Both HTML files, ‘header.html’ and ‘body.html’ are used by the function to create the HTML-formatted message, but before that, the ‘body.html’ is loaded in memory and edited.

The following placeholders exist in the ‘body.html’ file:

:agent:
:script:
:usergroup:
:profile:
:time:

The script uses FStrReplace() to find and replace the placeholders with the actual values obtained from the event handler and Silk Performer control functions such as GetAgent(), GetScriptName(), GetUserGroup() and GetProfile(). 

Edit the ‘body.html’ file and add new columns and placeholders, and extend the SendMail() instructions to comprise the new values.

This is how the placeholders are populated with the actual values of the error and runtime information:

The final step is sending the email. This sample code shows the contents of the DLL in Visual Studio:

Calling the .Net function involves:

  • load the .NET object (DLL).
  • define each parameter in the order the DLL expects to receive, using the DotNetSetString() function.
  • call the method using DotNetCallMethod().
  • get the return value status message using DotNetGetString().
  • Clear memory allocated to the dll and function using DotNetFreeObject().

The resulting email looks like this:

Download sample project here: EmailOnError.zip

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2015-04-22 19:08
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.