Custom Email Events Configuration
You can configure a new custom event, or modify an existing one.
Once you have filled the event form fields containing the main informations, generally contained in the “Main Data” Field Set, select the model (entity) for which to send the notification.
To enter the PHP code to configure the “Event Expression” and the notification recipients, expand the related scripting areas by clicking button with the “</> ” icon.
From the scripting areas, you can use the syntax $this->getModel() to access the instance of the selected model.
If the model is DeepActictivity – Activity, because you are creating or modifying an event for the notification when a commenti s added, with $this->getModel() you will access to the comment instance, not to the associated operation.
To access the related operation instance, use $this->getModel()->loadModelInstance().
Note: It is not possible to change the system email events configuration, in this case you need to duplicate the system email event and modify the duplicate.
EXAMPLE: CONFIGURE NOTIFICATION TO MANAGER GROUP FOR TICKETS WITH CRITICAL PRIORITY ASSIGNED TO THE FIRST LEVEL.
In this example we want to configure a notification event to send an email to “IT Managers” group if a ticket with “Critical” priority is created and assigned to the “IT First Level” group.
After defining the template and all the main event data follow these two steps.
STEP 1: “EVENT EXPRESSION” CONFIGURATION
The code in this field expresses the conditions for which a notification must be sent, in this case: “if a ticket with Critical priority is created and assigned to the IT First Level group“.
The following PHP code was used to express the condition:
// Retreive the operation object
$operation = $this->getModel();
// The IT First Level group entity_id
$itFirstLevelGroupId = 10;
// Check if Operation new and Assigned Group is defined and it's exactly IT Frist Level
if($operation->isObjectNew() &&
$operation->getAssignedGroupId() &&
$operation->getAssignedGroupId() == $itFirstLevelGroupId){
// "Critical" list value key
$criticalPriorityId = 1;
// If Operation has Critical priority then send the email notification
if($operation->getPriorityId() == $criticalPriorityId){
return true;
}
}
return false;
STEP 2: RECIPIENTS CONFIGURATION
To, Cc, Bcc fils are used to define to whom the notification should be sent, in this case: “to the IT Managers group“.
To set the recipients of the notification, the following PHP code has been inserted in the ‘To‘ field.
// The IT Managers group entity_id
$itManagerGroupId = 28;
// Load the IT Managers group object instance
$itManagerGroup = Deep::getModel('deep_group/group')->load($itManagerGroupId);
// Set message locale
$this->changeLanguage('en_US');
// If IT Managers group has its own email address (ex: mailing list)
if ($itManagerGroup->getEmail()) {
// Send email to its email address
$this->addTo($itManagerGroup->getEmail());
}
// Else send email to every user of the group
else {
// Load all users in IT Managers group
$managers = $itManagerGroup->loadUsers();
// Iterate over the collection and set the email address of each manager as recipient
foreach ($managers as $manager){
$this->addTo($manager->getEmail());
}
}
EXAMPLE 2: CONFIGURATION FOR SENDING NOTIFICATION TO CC INDICATED IN THE TICKET
In this example we want to modify the configuration of a notification event to the Requester User, to send the email by adding in Cc also the additional recipients indicated through a custom field in the operation.
Notification will be sent if the comment is visible to end users.
STEP 1: CREATE ADDITIONAL RECIPIENTS CUSTOM FIELD
Create a custom field in the DeepService – Operation model:
- Column Name: cust_additional_recipients
- Label: Additional Recipients
- Column Type: Don’t create DB column
- Element Type: Userassociation
Once you have created the custom field you need to add it to a formtemplate to start using it.
STEP 2: “CC” CONFIGURATION
In the Cc field all the users, associated to the operation through the custom field created in step1, are retreived and will be added in Cc to the notification email.
To set the additional recipients, use the following PHP code in the ‘Cc’ field.
You can configure a new custom event, or modify an existing one.
Once you have filled the event form fields containing the main informations, generally contained in the “Main Data” Field Set, select the model (entity) for which to send the notification.
To enter the PHP code to configure the “Event Expression” and the notification recipients, expand the related scripting areas by clicking button with the “</> ” icon.
From the scripting areas, you can use the syntax $this->getModel() to access the instance of the selected model.
If the model is DeepActictivity – Activity, because you are creating or modifying an event for the notification when a comment is added, with $this->getModel() you will access to the comment instance, not to the associated operation.
To access the related operation instance, use $this->getModel()->loadModelInstance().
//REGISTERED CC
$additionalRecipient = $this->getModel()->loadModelInstance()->loadUserAssociations();
if ($additionalRecipient && is_array($additionalRecipient) && count($additionalRecipient) > 0){
foreach ($additionalRecipient as $ccUserType){
foreach ($ccUserType as $ccUsername){
$ccUser = Deep::getModel('deep_admin/user')->loadByUsername($ccUsername);
$this->addCc($ccUser->getEmail());
}
}
}
Also, use the following PHP code in the ‘Cc’ field to notify unregistered CC users.
//UNREGISTERED CC
$additionalUnregisteredRecipient = $this->getModel()->loadModelInstance()-> getCustOperationCcUnregistered();
if ($additionalUnregisteredRecipient){
$additionalUnregisteredRecipientArray = explode(';',$additionalUnregisteredRecipient);
if(is_array($additionalUnregisteredRecipientArray) && count($additionalUnregisteredRecipientArray) >0){
foreach ($additionalUnregisteredRecipientArray as $ccUnregisterdUser){
$this->addCc(trim($ccUnregisterdUser));
}
}
}