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:

<?php echo Deep::helper('deep_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:

<?php 
$requesterUser = $this->getModel()->getRequesterUser();
$assignedUser = $this->getModel()->getAssignedUser();
?>

<?php $this->includeTemplate("header") ?>

<!-- Start of Main Content -->
<tr style="">
    <td bgcolor="#FFFFFF" align="center" style="">
        <table width="100%" align="center" cellpadding="0" cellspacing="0" bor-der="0" class="devicewidth" style="">
            <tbody style="">
            <!-- Start Spacer -->
            <tr>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td class="h26" height="36" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
            </tr>
            <!-- End Spacer -->
            <tr style="">
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td class="mktEditable content mktEditable content" id="edit_text_1" valign="middle" style="font-family:Calibri, Helvetica, sans-serif; font-size:16px; color:#505050; text-align:left; line-height:25.6px; font-weight:normal; text-transform:none;">
                    <p>
                        <br>
                        <?php echo Deep::helper('deep_email')->__('Dear %s', $this->getModel()->getAssignedUser()->getDisplayUsername())?>,<br>
                        <?php $url = $this->getModel()->getAssignedUser()->isUser() ? $this->getModel()->getPortalUrl() : $this->getModel()->getUrl(); ?>
                        <?php echo Deep::helper('deep_email')->__('You have Re-cived a new ticket from Acme International')?> <b style="font-weight: 700;"><a href="<?php echo $url ?>"><?php echo $this->getModel()->getId()?></a></b> 
                        <br>
                        <br>
                        <strong><?php echo Deep::helper('deep_email')->__('Title')?></strong>:
                        <br><?php echo $this->getModel()->getTitle()?><br><br>
                        <strong><?php echo Deep::helper('deep_email')->__('Description')?></strong>:
                        <br><?php echo $this->getModel()->getDescription()?><br>
                        
                        <!-- Status -->
                        <?php if($this->getModel()->getStatus()):?>
                        <strong><?php echo Deep::helper('deep_email')->__('Status')?></strong>: 
                            <?php 
                            $statusList = Deep::helper('deep_list')->loadList(Deep_Service_Model_Operation::LIST_CODE_STATUS);
                            $statusValue = $statusList->getValue($this->getModel()->getStatus());
                            ?>
                            <br><?php echo Deep::helper('deep_email')->__($statusValue->getValueLabel()); ?><br><br>
                        <?php endif;?>
                        
                        <!-- Requester -->
                        <?php if($requesterUser && $requesterUser->getId()):?>
                            <strong><?php echo Deep::helper('deep_service')->__('Requester User')?></strong>: 
                            <?php if($this->getModel()->getRequesterUser()->getAvatar()):?>
                            <br><img src="<?php echo $this->getModel()->getRequesterUser()->getAvatarUrl() ?>" border="0" style="-ms-interpolation-mode: bicubic;" width="16" />
                            <?php endif;?>
                            &nbsp;&nbsp;&nbsp;<?php echo $this->getModel()->getRequesterUser()->getDisplayUsername() ?><br><br>
                        <?php endif;?>
                        
                        <!-- Assigned -->
                        <?php if($assignedUser && $assignedUser->getId()):?>
                        <strong><?php echo Deep::helper('deep_service')->__('Assigned User')?></strong>: 
                            <?php if($this->getModel()->getAssignedUser()->getAvatar()):?>
                            <br><img src="<?php echo $this->getModel()->getAssignedUser()->getAvatarUrl() ?>" border="0" style="-ms-interpolation-mode: bicubic;" width="16" />
                            <?php endif;?>
                            &nbsp;&nbsp;&nbsp;<?php echo $this->getModel()->getAssignedUser()->getDisplayUsername() ?><br><br>
                        <?php endif;?>

                        <!-- Urgency -->
                        <?php if($this->getModel()->getUrgencyId()):?>
                        <strong><?php echo Deep::helper('deep_email')->__('Urgency')?></strong>: 
                            <?php 
                            $urgencyList = Deep::helper('deep_list')->loadList(Deep_Service_Model_Operation::LIST_CODE_URGENCY);
                            $urgencyValue = $urgencyList->getValue($this->getModel()->getUrgencyId());
                            ?>
                            <br><?php echo Deep::helper('deep_email')->__($urgencyValue->getValueLabel()); ?><br><br>
                        <?php endif;?>
                        
                        
                        <!-- Priority -->
                        <?php if($this->getModel()->getPriorityId()):?>
                        <strong><?php echo Deep::helper('deep_email')->__('Priority')?></strong>: 
                            <?php 
                            $priorityList = Deep::helper('deep_list')->loadList(Deep_Service_Model_Operation::LIST_CODE_PRIORITY);
                            $priorityValue = $priorityList->getValue($this->getModel()->getPriorityId());
                            ?>
                            <br><?php echo Deep::helper('deep_email')->__($priorityValue->getValueLabel()); ?><br><br>
                        <?php endif;?>
                        
                        <!-- Solution -->
                        <?php if($this->getModel()->getSolution()):?>
                        <strong><?php echo Deep::helper('deep_email')->__('Solution')?></strong>: 
                        <br><?php echo $this->getModel()->getSolution()?>
                        <br>
                        <?php endif;?>
                    </p>
                </td>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
            </tr>
            <!-- Start Spacer -->
            <tr>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td height="30" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
            </tr>
            <!-- End Spacer -->
            </tbody>
        </table> 
    </td>
</tr>
<!-- End of Main Content -->
<!-- End of Main Content -->
<?php $url = $this->getModel()->getUrlByUser($assignedUser); ?>
<!-- start of Button -->
<tr style="">
    <td bgcolor="#FFFFFF" align="center" class="mktEditable" id="edit_cta_button" style="">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tbody>
            <tr>
                <td class="w22" width="41" style="font-size: 1px; line-height: 1px;">&nbsp;</td>
                <td align="left">
                    <table class="button" cellpadding="0" cellspacing="0" bor-der="0" align="left" bgcolor="#0080ff" style="-webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px;">
                        <tbody>
                        <tr>
                            <td width="518" align="center" valign="middle" height="65">
                                <span style="color: #ffffff; text-decoration: none;">
                                        <a class="mobButton mktNoTok" href="<?php echo $url ?>" style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; color: #ffffff; display: block; height: 65px; mso-line-height-rule: exactly; line-height: 65px; font-weight: normal; text-decoration: none; text-align: center!important;" target="_blank" title="Link al ticket">
                                            <?php echo Deep::helper('deep_email')->__('Go to the Ticket')?>
                                        </a>
                                </span>
                            </td>
                        </tr>
                        </tbody>
                    </table> </td>
                <td class="w22" width="41" style="font-size: 1px; line-height: 1px;">&nbsp;</td>
            </tr>
            </tbody>
        </table>
    </td>
</tr>
<!-- end of Button -->


<?php $this->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:

<?php $line = $this->getModel()?>
The contract line <?php echo $line->getLineNumber() . ' - ' . $line->getName()?> of the contract <?php echo $line->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:

<?php $this->includeTemplate("header") ?>
<style>
    .table{
        width: 100%;
        margin-left:auto;
        margin-right: auto;
    }
    .tr,.td{
        width: 100%;text-align: center; 
        vertical-align: middle;
    }
    .cust-container{
        display: flex;
        justify-content: center;
        margin-left: auto;
        margin-right: auto;
    }
      
</style>
<!-- Start of Main Content -->
<tr style="">
    <td bgcolor="#FFFFFF" align="center" style="">
        <table width="100%" align="center" cellpadding="0" cellspacing="0" border="0" class="devicewidth" style="">
            <tbody style="">
            <!-- Start Spacer -->
            <tr>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td class="h26" height="36" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
            </tr>
            <!-- End Spacer -->
            <tr>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td class="mktEditable content mktEditable content" id="edit_text_1" valign="middle" style="font-family:Calibri, Helvetica, sans-serif; font-size:16px; color:#505050; text-align:left; line-height:25.6px; font-weight:normal; text-transform:none;">
                    <p>
                        <br>
                            <div class="cust-container">
                                <?php $residuo = sprintf("%02d:%02d", floor($line->getRemainingTime()/3600), floor(($line->getRemainingTime()/60) %60))?>
                                The Contract Line &nbsp;<b><?php echo $line->getLineNumber() . ' - ' . $line->getName()?> </b> &nbsp;<?php echo " is going low ({$residuo} Hours remaning ) ";?>
                             </div>
                        <br>
                        <br>
                       
                        <table class="table">
                            <tr class="tr">
                                <td>
                                    <strong><?php echo Deep::helper('deep_email')->__('Total Time')?></strong>:
                                    <br><?php echo sprintf("%02d:%02d", floor($line->getTotalTime()/3600), floor(($line->getTotalTime()/60) %60))?><br><br>
                                </td>
                                <td>
                                      <strong><?php echo Deep::helper('deep_email')->__('Remaining Time')?></strong>:
                                      <br><?php echo sprintf("%02d:%02d", floor($line->getRemainingTime()/3600), floor(($line->getRemainingTime()/60) %60))?><br><br>
                                </td>
                            </tr>
                            <tr class="tr">
                                <td>
                                      <strong><?php echo Deep::helper('deep_email')->__('Name')?></strong>:
                                      <br><?php echo $contract->getName()?><br><br>
                                </td>
                                <td>
                                      
                                     <strong><?php echo Deep::helper('deep_email')->__('Customer Company')?></strong>:
                                     <br><?php echo $company && $company->getId() ? $company->getName() : ''?><br><br>
                                </td>
                            </tr>
                        </table>
                        
                        
                      
                        
                      
                      
                    </p>
                </td>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
            </tr>
            <!-- Start Spacer -->
            <tr>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td height="30" style="font-size:1px; line-height:1px;">&nbsp;</td>
                <td class="w22" width="41" style="font-size:1px; line-height:1px;">&nbsp;</td>
            </tr>
            <!-- End Spacer -->
            </tbody>
        </table>
    </td>
</tr>
<!-- End of Main Content -->
<?php $this->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, we set the query builder as follows:

At this point, you will need to click the “Save” or “Apply” button.