Hi Team,
I have tried the schedulers for dynamically changing the field values based on two conditions
module > coll_otp_manager
fields > creationtime, status
the condition is
if the status field is active && creationtime is 45s less than current time(creationtime +45s)
then the action could be
status is “Expired”
for this i have created a scheduler
and i have created the logic hook in
D:\httpd-2.4.57\Apache24\htdocs\suitecrm841\public\legacy\modules\Schedulers\_AddJobsHere.php
in the _AddJobsHere.php I have defined my custom hook in the job_strings
$job_strings = array(
0 => 'refreshJobs',
1 => 'pollMonitoredInboxes',
2 => 'runMassEmailCampaign',
3 => 'pruneDatabase',
4 => 'trimTracker',
5 => 'pollMonitoredInboxesForBouncedCampaignEmails',
6 => 'pollMonitoredInboxesAOP',
7 => 'aorRunScheduledReports',
8 => 'processAOW_Workflow',
9 => 'sendEmailReminders',
10 => 'cleanJobQueue',
11 => 'removeDocumentsFromFS',
12 => 'trimSugarFeeds',
13 => 'syncGoogleCalendar',
14 => 'runElasticSearchIndexerScheduler',
**15 => 'expireOtpRecords',**
);
and my expireOtpRecords() {} =>
function expireOtpRecords() {
$GLOBALS['log']->debug('entered into expireOtpRecords method ');
$db = DBManagerFactory::getInstance();
$currentDateTime = new DateTime('now', new DateTimeZone('UTC'));
$currentDateTimeFormatted = $currentDateTime->format('Y-m-d H:i:s');
// Add debug statement to log the current date and time
$GLOBALS['log']->debug('Current_Date_and_Time: ' . $currentDateTimeFormatted);
// Query to select all 'Active' OTP records that are older than 45 seconds
$query = "SELECT id, creationtime FROM coll_otp_manager WHERE status = 'Active' AND TIMESTAMPDIFF(SECOND, creationtime, '{$currentDateTimeFormatted}') > 45";
$result = $db->query($query);
while ($row = $db->fetchByAssoc($result)) {
$otpBean = BeanFactory::retrieveBean('coll_OTP_Manager', $row['id']);
if ($otpBean) {
// Add debug statement to log the OTP record ID being processed
$GLOBALS['log']->debug('Processing OTP Record ID: ' . $otpBean->id);
$otpBean->status = 'Expired';
$otpBean->save();
// Add debug statement to confirm the status update
$GLOBALS['log']->debug('Status updated to Expired for OTP Record ID: ' . $otpBean->id);
}
}
}
and created batch files to run the SuiteCRM schedulers, run using Windows Scheduled Tasks
as mentioned in the suitecrm I have created my batch file like this
@echo off
cd /D D:\httpd-2.4.57\Apache24\htdocs\suitecrm841\public\legacy
php.exe -f cron.php
hope I’m done with all the steps, still, the task is not yet updated accordingly, what needs to be fixed and checked further? some one please help me with this!