I made a Schedule job programmaticaly with intention to create alerts from each record of a module (pma_airplane with label “Aeronave”) to a specific user.
I can see it from Scheluder jobs module and can create one that executes each minute (just to test).
The thing is the registry i can see the job is performed but the alerts are not generated
Mi code is:
<?php
/*
* Nombre del método al array $job_strings
* este es el método que este planificador llamará
*/
$job_strings[] = 'setAlertCritical';
function setAlertCritical(){
error_log("I'm here", 3,"/var/www/html/suitecrm/suitecrm.log");
// get the airplanes
$aiplaneBean = BeanFactory::getBean('Aeronave'); // This is the label of the module, also tried with the name of that module
$airplaneList = $ $airplaneBean->get_full_list(
'name',
);
foreach($airplaneList as $airplane){
// Alert for each airplane
$alert = BeanFactory:newBean('Alerts');
$alert->name = "Alert";
$alert->description = '¡Check this alert!';
$alert->url_redirect = 'index.php';
$alert->assigned_user_id = 'id-from-dat4b4se;
$alert->type = 'info';
$alert->is_read = 0;
$alert->save();
}
}
Juan, I don’t know the answer to your question, but since you’re obviously doing a lot of development work lately, I would like to ask you if you have XDEBUG set up so you can debug your code?
Basic instructions to create custom Schedulers, from Jim Mackin’s book:
create a file in
custom/Extension/modules/Schedulers/Ext/ScheduledTasks/cleanMeetingsScheduler.php
Sample content:
<?php
/*
* We add the method name to the $job_strings array.
* This is the method that jobs for this scheduler will call.
*/
$job_strings[] = 'cleanMeetingsScheduler';
/**
* Example scheduled job to change any 'Planned' meetings older than a month
* to 'Not Held'.
* @return bool
*/
function cleanMeetingsScheduler(){
//Get the cutoff date for which meetings will be considered
$cutOff = new DateTime('now - 1 month');
$cutOff = $cutOff->format('Y-m-d H:i:s');
//Get an instance of the meetings bean for querying
//see the Working With Beans chapter.
$bean = BeanFactory::getBean('Meetings');
//Get the list of meetings older than the cutoff that are marked as Planned
$query = "meetings.date_start < '$cutOff' AND meetings.status = 'Planned'";
$meetings = $bean->get_full_list('',$query);
foreach($meetings as $meeting){
//Mark each meeting as Not Held
$meeting->status = 'Not Held';
//Save the meeting changes
$meeting->save();
}
//Signify we have successfully ran
return true;
}
add a language file in
custom/Extension/modules/Schedulers/Ext/Language/en_us.cleanMeetingsScheduler.php
with
<?php
//We add the mod string for our method here.
$mod_strings['LBL_CLEANMEETINGSSCHEDULER'] = 'Mark old, planned meetings as Not Held';
Do a Quick Repair and Rebuild, go to Admin/Schedulers and you should see it there.