[Vtigercrm-developers] Workflow / Event Handler timing question
Alan Lord
alanslists at gmail.com
Mon Dec 10 10:03:59 GMT 2018
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot from 2018-12-10 09-56-28.png
Type: image/png
Size: 75775 bytes
Desc: not available
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20181210/bf37b6ca/attachment-0001.png>
More information about the vtigercrm-developers
mailing list