Configure an escalation rule that generates other entities

Suppose you want to configure an escalation rule that gives high priority to all tickets whose requesting company is “Acme International” and that adds a comment not visible to users that reports some quick contact information for the operator who will have to handle the request.

To do this you will need to go to the System -> Service Configuration -> Escalation Rule menu.

Here, you will need to click on the “Add Rule” button.

Now the following screen will open:

At this point, we configure the “Name” field as “High Priority Acme International” and load Primary Contact Information”.

We set the “Model Alias” field to “DeepService – Operation”.

Now configure the Field “Level” to 0 and Next Level to 1, that is, this rule will process all the tickets whose level is zero and then change this level to 1 so as not to reprocess the same tickets.

Please pay attention that in the case of several escalation rules active at the same time and potentially changing the level.

At this point, we set the field “Cron Expression” Every 5 minutes using the drop-down menu located below the field itself.

As the last step of this first phase, click on “Save” or “Apply” to save the rule.

Configuring Query Builders

Now configure in the newly created rule the query builder “Escalate all Records with following values (Main Filter)” like this:

Now configure in the rule just created the query builder “Set Records values to” like this:

At this point in the “Output section (Script)” we are going to insert the following code:

$entityId = $this->getModelOutput()->getId();
$company = $this->getModelOutput()->loadRequesterCompany();
if($company && $company->getId()){
    $primaryContactUserName = $company->getData('primary_contact');
    $primaryContact = Deep::getModel('deep_admin/user')->loadByUsername($primaryContactUserName);
    if($primaryContact && $primaryContact->getId()){
        $primaryContactName = $primaryContact->getFirstname() . " " . $primaryContact->getLastname();
        $primaryContactEmail = $primaryContact->getEmail() ? $primaryContact->getEmail() : "" ;
        $primaryContactPhone = $primaryContact->getPhone() ? $primaryContact->getPhone() : "";
        $Description = nl2br("\n=================================================================\n 
                                 Nome Referente: {$primaryContactName}\n
                                 Telefono Referente: {$primaryContactPhone}\n 
                                 Email Referente: {$primaryContactEmail}\n 
        $comment =  Deep::getModel('deep_activity/activity');

Now we can click on “Save” or “Apply”.