Dear community,
I am working with V13.0.0 and I have the following business case:
A custom module "Claim". This module is related to the Cases module (1:N). There can be several claims of different or the same type under the case. Each claim can be answered individually. The answers are created by the email module attached to the claim.
The Claim Module has a field "Due Date".
I want the related draft email to be sent only when this "Due Date" is reached. The "Send"-button in the "Compose Email View" of the email. is hidden. This way it is only possible to create a "Draft".
Scheduler is created at the Scheduler Module
Here is what I have done so far.
Code: custom/Extension/modules/Schedulers/Ext/ScheduledTasks/sendClaimDraftEmails.php
function sendDraftEmails() { $emails = BeanFactory::newBean('Emails'); $query = new SugarQuery(); $query->select(array('id', 'mg_email_send_date_c')); $query->from($emails, array('team_security' => false)); $query->where()->equals('status', 'draft'); $query->where()->queryAnd()->equals('status', 'draft')->notNull('mg_email_send_date_c'); $draft_emails = $query->execute(); _ppl($draft_emails); $currentDate = strtotime(date('Y-m-d H:i:s')); _ppl($currentDate); if (!empty($draft_emails)) { foreach($draft_emails as $email){ $emailSendDate = strtotime($email['mg_email_send_date_c']); _ppl($emailSendDate); if ($currentDate >= $emailSendDate) { $email_bean = BeanFactory::retrieveBean('Emails', $email['id']); $email_bean->type = "out"; $email_bean->state = Email::STATE_READY; if ($email_bean->send()) { $email_bean->status = 'sent'; $email_bean->state = Email::STATE_ARCHIVED; } else { $email_bean->status = 'send_error'; $email_bean->state = Email::STATE_DRAFT; } $email_bean->save(); } } } return true; }
I found the email send approach above on the www, without mention the Sugar version. It Looks like, this does not work with Sugar V13. I searched in Dev Club and Sugar Documents as well, without success.
Hope I have made myself clear..
Does anyone have an idea how I can achieve this?
Thank you very much for any help
Rene