Hi everyone,
With the request: Create a trigger template to track tickets with the status "resolved" after a specified time, it will automatically send reminder emails to relevant parties in the Notification -> Trigger configuration.
I want to create a notification about sending reminder email in Notification.
- I tried adding a TriggerOnRemind class in /core/trigger.class.inc.php file
With field: date_remind is the time entered to send reminder email with condition: resolution_date + date_remind >= NOW()
I also added a real time check function in /core/ormstopwatch.class.inc.php
classCheckRemindTriggerimplementsiBackgroundProcess{publicfunctionGetPeriodicity(){return600;// 10 minutes in seconds}publicfunctionProcess($iTimeLimit){$aList=array();foreach(MetaModel::GetClasses()as$sClass){$sNow=date(AttributeDateTime::GetSQLFormat());// Fetch triggers that are due for reminder$oTriggerSet=newDBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnRemind WHERE date_remind != 'NULL'"),array(),array('date_remind'=>true));$oTriggerSet->OptimizeColumnLoad(array('TriggerOnRemind'=>array('date_remind')));while((time()<$iTimeLimit)&&($oTrigger=$oTriggerSet->Fetch())){$dateRemindDuration=$oTrigger->Get('date_remind');$iDateRemindInterval=$this->parseDuration($dateRemindDuration);$sExpression="SELECT $sClass WHERE status = 'resolved' AND DATE_ADD(resolution_date, INTERVAL :date_remind SECOND) <= :now AND check_remind != 'yes'";$oFilter=DBObjectSearch::FromOQL($sExpression);$oSet=newDBObjectSet($oFilter,array(),array('date_remind'=>$iDateRemindInterval,'now'=>$sNow));$oSet->OptimizeColumnLoad(array($sClass=>array('status','resolution_date')));while((time()<$iTimeLimit)&&($oObj=$oSet->Fetch())){$sClass=get_class($oObj);$aList[]=$sClass.'::'.$oObj->GetKey();// Execute remind actions$this->ExecuteRemindActions($oTrigger,$oObj);// Update last_remind_sent to current time in trigger$oObj->Set('check_remind','yes');if($oTrigger->IsModified()){CMDBObject::SetTrackInfo("Automatic - reminder sent");$oTrigger->DBUpdate();}}}}$iProcessed=count($aList);return"Processed $iProcessed reminder(s):".implode(", ",$aList);}// Helper function to parse duration format like 'P3D' to secondsprivatefunctionparseDuration($duration){$interval=newDateInterval($duration);return($interval->days*86400)+($interval->h*3600)+($interval->i*60)+$interval->s;}privatefunctionExecuteRemindActions($oTrigger,$oObj){$aActions=$oTrigger->Get('actions');foreach($aActionsas$aActionData){$sVerb=$aActionData['verb'];$aParams=$aActionData['params'];$aValues=array();foreach($aParamsas$def){if(is_string($def)){$aValues[]=$def;}else{$sParamType=array_key_exists('type',$def)?$def['type']:'string';switch($sParamType){case'int':$value=(int)$def['value'];break;case'float':$value=(float)$def['value'];break;case'bool':$value=(bool)$def['value'];break;case'reference':$value=${$def['value']};break;case'string':default:$value=(string)$def['value'];}$aValues[]=$value;}}$aCallSpec=array($oObj,$sVerb);call_user_func_array($aCallSpec,$aValues);}}}
I saw the CheckRemindTrigger running under the hood but it didn't send the email with the notification config I set up.
Please help me check and fix this! Thanks a lot.
Last edit: Edward 2024-07-25
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everyone,
With the request: Create a trigger template to track tickets with the status "resolved" after a specified time, it will automatically send reminder emails to relevant parties in the Notification -> Trigger configuration.
I want to create a notification about sending reminder email in Notification.
- I tried adding a TriggerOnRemind class in /core/trigger.class.inc.php file
I saw the CheckRemindTrigger running under the hood but it didn't send the email with the notification config I set up.
Please help me check and fix this! Thanks a lot.
Last edit: Edward 2024-07-25