[Vtigercrm-developers] Workflow / Event Handler timing question

Tony Sandman tonysandman999 at gmail.com
Tue Dec 11 00:24:10 GMT 2018


It happen on every save or first? Maybe delayed execution? Workflow
Designer got that function

T.

On Mon, Dec 10, 2018 at 5:05 PM Alan Lord <alanslists at gmail.com> wrote:

> Am getting rather frustrated by this...
>
> I've added a new field to the Leads module called "Previously Assigned
> To". It's a UIType 53 and stores a user id value.
>
> I created an Event Handler for Leads that is listening for the
> vtiger.entity.aftersave.final event. It examines the VTEntityDelta and
> if the "assigned_user_id" changes, it updates my new Previously Assigned
> To field with the old_value of the Delta using vtws_revise (to trigger
> the new workflow below). This is working - so on-screen when viewing the
> Lead, it shows the new Assigned To value and the Previously Assigned To
> field shows the old Assigned To value.
>
> I then created a Workflow for the Leads module to send an Email to the
> Previously Assigned To user, with a trigger when the Previously Assigned
> To field changes, to inform them that they no longer own this record.
>
> The workflow is triggered by the Event handler as I would expect. BUT
> this workflow retrieves the older value of the Previously Assigned To
> field (yet it has the right Assigned To value). So it sends the email to
> the previously Previously Assigned To ;-)
>
>
> Here's the relevant Event Handler code:
>
> >         if($handlerType == 'vtiger.entity.aftersave.final' &&
> in_array($moduleName, $modules)) {
> >             // Use Admin user so we can make the field Read Only in
> profiles
> >             $user = Users::getActiveAdminUser();
> >             $recordId = $entityData->getId();
> >             $vtEntityDelta = new VTEntityDelta();
> >             $prevAssTo = $vtEntityDelta->getOldValue($moduleName,
> $recordId, 'assigned_user_id');
> >             if($prevAssTo) {
> >                 $prevAssTo = vtws_getWebserviceEntityId('Users',
> $prevAssTo);
> >                 try {
> >                     $wsid = vtws_getWebserviceEntityId($moduleName,
> $recordId);
> >                     $data = array('prev_assigned_to' => $prevAssTo, 'id'
> => $wsid);
> >                     $ent = vtws_revise($data, $user);
> >                 } catch (WebServiceException $ex) {
> >                     $log->debug($ex->getMessage());
> >                 }
> >             }
> >         }
> >         $log->debug("Exiting Event Handler class: " . __CLASS__);
>
> What is wrong? How can I get the timing right?
>
> TIA
>
> Al
> _______________________________________________
> http://www.vtiger.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20181211/4b440e4e/attachment.html>


More information about the vtigercrm-developers mailing list