function handleEvent($eventName, $data)
 {
     if ($eventName == 'vtiger.entity.beforesave') {
         // Entity is about to be saved, take required action
     }
     if ($eventName == 'vtiger.entity.aftersave') {
         $db = PearDatabase::getInstance();
         $relatedToId = $data->get('related_to');
         if ($relatedToId) {
             $moduleName = getSalesEntityType($relatedToId);
             $focus = CRMEntity::getInstance($moduleName);
             $focus->retrieve_entity_info($relatedToId, $moduleName);
             $focus->id = $relatedToId;
             $fromPortal = $data->get('from_portal');
             if ($fromPortal) {
                 $focus->column_fields['from_portal'] = $fromPortal;
             }
             $entityData = VTEntityData::fromCRMEntity($focus);
             $wfs = new VTWorkflowManager($db);
             $relatedToEventHandler = new VTWorkflowEventHandler();
             $relatedToEventHandler->workflows = $wfs->getWorkflowsForModuleSupportingComments($entityData->getModuleName());
             $wsId = vtws_getWebserviceEntityId($entityData->getModuleName(), $entityData->getId());
             $fromPortal = $entityData->get('from_portal');
             $util = new VTWorkflowUtils();
             $entityCache = new VTEntityCache($util->adminUser());
             $entityCacheData = $entityCache->forId($wsId);
             $entityCacheData->set('from_portal', $fromPortal);
             $entityCache->cache[$wsId] = $entityCacheData;
             $relatedToEventHandler->handleEvent($eventName, $entityData, $entityCache);
             $util->revertUser();
         }
     }
 }