Escalation rule that sends an email notification
In Deepser, Escalation rules can trigger email notifications. This allows you to use escalation rules to eliminate alerts when specific events occur. In the following example, we are going to create an escalation rule that will notify the user in case the requesting company is Acme International. In this example, we will also use the escalation rule created in the previous example.
E-MAIL TEMPLATE CREATION
In order to send the email notification to the assignee user, it will be necessary to create an email event with its associated mail template that will be used by Deepser to send the email from the escalation rule. To create a custom, you will need to go to the System -> Tools -> Email -> Template menu. Then you will need to click on the”Add Mail Template” button. In the screen that will open you will need to define a name for the template, to do this, simply enter the desired name in the “Name” field. Next we will define a code for the template, filling in the “Code” field. At this point, it will be possible to insert in the”Subject”section the php code that will compose the subject of the email. You can use the following code as a reference to compose the subject of the email:
__('DEEPSER – New ticket from Acme International')?>
Now, it will be possible to insert in the “Body” section, which will represent the content of the message, the PHP / HTML code that will be used to generate the body of the mail.
You can use the following code as a reference when creating the body:
getModel()->getRequesterUser();
$assignedUser = $this->getModel()->getAssignedUser();
?>
includeTemplate(“header”) ?>
__(‘Dear %s’, $this->getModel()->getAssignedUser()->getDisplayUsername())?>,
getModel()->getAssignedUser()->isUser() ? $this->getModel()->getPortalUrl() : $this->getModel()->getUrl(); ?>
__(‘You have Re-cived a new ticket from Acme International’)?> ”>getModel()->getId()?>
__(‘Title’)?>:
getModel()->getTitle()?>
__(‘Description’)?>:
getModel()->getDescription()?>
getModel()->getStatus()):?>
__(‘Status’)?>:
loadList(Deep_Service_Model_Operation::LIST_CODE_STATUS);
$statusValue = $statusList->getValue($this->getModel()->getStatus());
?>
__($statusValue->getValueLabel()); ?>
getId()):?>
__(‘Requester User’)?>:
getModel()->getRequesterUser()->getAvatar()):?>
getModel()->getRequesterUser()->getAvatarUrl() ?>” border=”0″ style=”-ms-interpolation-mode: bicubic;” width=”16″ />
getModel()->getRequesterUser()->getDisplayUsername() ?>
getId()):?>
__(‘Assigned User’)?>:
getModel()->getAssignedUser()->getAvatar()):?>
getModel()->getAssignedUser()->getAvatarUrl() ?>” border=”0″ style=”-ms-interpolation-mode: bicubic;” width=”16″ />
getModel()->getAssignedUser()->getDisplayUsername() ?>
getModel()->getUrgencyId()):?>
__(‘Urgency’)?>:
loadList(Deep_Service_Model_Operation::LIST_CODE_URGENCY);
$urgencyValue = $urgencyList->getValue($this->getModel()->getUrgencyId());
?>
__($urgencyValue->getValueLabel()); ?>
getModel()->getPriorityId()):?>
__(‘Priority’)?>:
loadList(Deep_Service_Model_Operation::LIST_CODE_PRIORITY);
$priorityValue = $priorityList->getValue($this->getModel()->getPriorityId());
?>
__($priorityValue->getValueLabel()); ?>
getModel()->getSolution()):?>
__(‘Solution’)?>:
getModel()->getSolution()?>
getModel()->getUrlByUser($assignedUser); ?>
includeTemplate(“footer”) ?>
And click on the “Save” or”Apply”button
EMAIL EVENT CREATION
To create a custom mail event you will need to go to the System -> Tools -> Email -> Event menu. At this point you will need to click on the”Add Event” button. At this moment, it will be necessary to give a name to the event by filling in the “Name” field. We define Whether to send attachments by changing the value of the field”Send Attachments” to “No”. Now in the “Email Template” field we select the template created in the previous point of this guide. In the “Event Trigger” section, select “DeepService – Operation” in the “Model” field In the “Event Expression”entry. We insert the following code:
// if the Company is Acme International
if($this->getModel()->getData("requester_company_id") == Deep::getModel("deep_company/company")->load("ACME International",'name')->getId() ){
if ($this->getModel()->getData('escalation_rule')){
return true;
}
}
return false;
In the “To” section We insert the following code:
$user = $this->getModel()->getAssignedUser();
if ($user && $user->getId()){
$this->changeLanguage($user->getLocale());
$this->addTo($user->getEmail());
}
At this point, we can go to click the “Save” or “Apply” button Now the event will have been saved
ASSIGNING THE MAIL EVENT TO THE ESCALATION RULE
To assign the mail event to the escalation rule you will need to go to the menu: System -> Service Configuration. Here you will need to go to the previously created rule or any escalation rule you want to change. In the Escalation Rule screen you will need to select the Created event from the drop-down menu that will appear by clicking the “Email Event” field. At this point you will need to click the “Save” or”Apply” button.
EXAMPLE: SENDING EMAIL TO THE OPERATOR WHEN THE NUMBER OF HOURS IS LESS THAN 4
In this example, suppose you want to email the administrator when the number of hours remaining in a contract line is less than 4
E-MAIL TEMPLATE CREATION
In order to send the email notification to the administrator, it will be necessary to create an email event with its associated mail template that will be used by Deepser to send the email from the escalation rule. To create a custom mail event, you will need to go to the System -> Tools -> Email -> Template menu. Then you will need to click on the”Add Mail Template” button. In the screen that will open you will need to define a name for the template, to do this, simply enter the desired name in the “Name” field. Next we will define a code for the template, filling in the “Code” field. At this point, it will be possible to insert in the”Subject”section the php code that will compose the subject of the email. You can use the following code as a reference to compose the subject of the email:
getModel()?>
The contract line getLineNumber() . ' - ' . $line->getName()?> of the contract loadContract()->getContractNumber() . ' - ' . $line->loadContract()->getName()?> is going low
Now it will be possible to insert in the “Body” section, which will represent the content of the message, the PHP / HTML code that will be used to generate the body of the mail. You can use the following code as a reference when creating the body:
includeTemplate("header") ?>
getRemainingTime()/3600), floor(($line->getRemainingTime()/60) %60))?>
The Contract Line getLineNumber() . ' - ' . $line->getName()?>
__('Total Time')?>:
getTotalTime()/3600), floor(($line->getTotalTime()/60) %60))?>
__('Remaining Time')?>:
getRemainingTime()/3600), floor(($line->getRemainingTime()/60) %60))?>
__('Name')?>:
getName()?>
__('Customer Company')?>:
getId() ? $company->getName() : ''?>
includeTemplate("footer") ?>
And click on the “Save” or”Apply” button.
EMAIL EVENT CREATION
To create a custom mail event, you will need to go to the System -> Tools -> Email -> Event menu. At this point, you will need to click on the”Add Event” button. At this point, it will be necessary to give a name to the event by filling in the “Name” field. We define Whether to send attachments by changing the value of the field”Send Attachments” to “No”. Now in the “Email Template” field, we select the template created in the previous point of this guide. In the “Event Trigger” section, select “DeepService – Operation”in the “Model” field In the “Event Expression”entry. We insert the following code:
if ($this->getModel()->getData('escalation_rule')){
return true;
}
return false;
In the “To” section We insert the following code:
$adminUserToNotify = 'admin';
$admin = Deep::getModel('deep_admin/user')->loadByUsername($adminUserToNotify);
if($admin && $admin->getId()){
$adminEmail = $admin->getEmail();
if($adminEmail){
$this->changeLanguage($admin->getLocale());
$this->addTo($adminEmail);
}
}
At this point, we can go to click the “Save” or”Apply” button Now the event will have been saved
ASSIGNING THE MAIL EVENT TO THE ESCALATION RULE
To assign the mail event to the escalation rule you will need to go to the menu: System -> Service Configuration. Here you will need to go to the previously created rule or any escalation rule you want to change. In the Escalation Rule screen, you will need to select the Created event from the drop-down menu that will appear by clicking the “Email Event” field. At this point, We are going to configure the “Level” field to 0 and the “Next Level” field to 1. Since we do not want to receive the notification every time the rule runs, but only the first time. Finally we are going to configure the field “Cron Expression”at 5 minutes using the drop-down menu located below the field itself. In the “Escalate all Records with following values (Main Filter)” field.At this point, you will need to click the “Save” or “Apply” button.