0

Did anyone try this?

I have a custom module I created a field next visit, I want to make an event after saving my record in my custom module based on next visit field date. here's the following code tried.

public function process(Vtiger_Request $request) {
 try {
  $CustomSaveEvents= $this->saveAppointmentRecord();
 } catch (Exception $e) {
  throw new Exception($e->getMessage());
 }
}

public function saveAppointmentRecord() {
try {
    $linkModule ="Events";
    $recordModel1 = Vtiger_Record_Model::getCleanInstance($linkModule);
    $recordModel1->set('subject', "Sample");
    $recordModel1->set('mentorid',"6411");
    $recordModel1->set('apprenticeid',"10849");
    $recordModel1->set('due_date', '2022-10-24');
    $recordModel1->set('time_end','2022-10-24');
    $recordModel1->set('mode', 'create');
    $recordModel1->save();
    $this->savedRecordId = $recordModel1->getId();

        return $recordModel1;
    }catch (Exception $e) {
        throw new Exception($e->getMessage());
    }
}

But it didn't work. any can help me? Thank you in advance!

calendar will show new record

Mart-ASE
  • 1
  • 1

2 Answers2

0

I have recently done something similar, but with the "Products" and "Documents" modules.

The crm was hanging when executing save(), until I realized that it was caused by some aftersave events, the ones related to VTEntitydelta.

My solution was to disable these events before save():

$desactivaHandlers = "UPDATE vtiger_eventhandlers SET is_active = 0 WHERE dependent_on LIKE '[\"VTEntityDelta\"]'";
$result = $adb->pquery($desactivaHandlers);

And reactivate it again after the save():

$reactivaHandlers = "UPDATE vtiger_eventhandlers SET is_active = 1 WHERE dependent_on LIKE '[\"VTEntityDelta\"]'";
$result = $adb->pquery($reactivaHandlers);

Hope it helps!

psauleda
  • 60
  • 5
  • Thanks for your answer. What I am trying to do is create a new record in the calendar module after saving a new record from my custom module – Mart-ASE Nov 15 '22 at 08:40
-1

Why you are coding when it's possible to do it without coding? You can use Workflows to create an Event on save the event. Here is the link to which you can refer to configure the workflow in CRM. This Video will not have full-fill your exact requirements, but you can refer to understand how Workflow configuration works.

  1. https://www.youtube.com/watch?v=x2j-ZQTzXps
  2. https://www.youtube.com/watch?v=jwipywUzlzo

enter image description here

Milan Malani
  • 1,818
  • 1
  • 22
  • 34
  • Thanks for the answer What I want to achieve is to set the start date and end date for the calendar's new record based on the Next Visit field of my custom module. Also, the Create Event action in workflow is not available for my custom module as Target Module – Mart-ASE Nov 15 '22 at 09:40
  • To get the Event module in Workflow for your custom module, you have to add the Calendar/Event module as a related module. Also, Workflow allows selecting a date/DateTime field (Next Visit field) to set an Event date. – Milan Malani Nov 15 '22 at 09:44
  • I created a relationship here in the table vtiger_relatedlists is this right? but still don't show the create event in an add action. :( – Mart-ASE Nov 15 '22 at 10:21