<div dir="ltr"><div>It happen on every save or first? Maybe delayed execution? Workflow Designer got that function</div><div><br></div><div>T.<br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Dec 10, 2018 at 5:05 PM Alan Lord <<a href="mailto:alanslists@gmail.com">alanslists@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Am getting rather frustrated by this...<br>
<br>
I've added a new field to the Leads module called "Previously Assigned <br>
To". It's a UIType 53 and stores a user id value.<br>
<br>
I created an Event Handler for Leads that is listening for the <br>
vtiger.entity.aftersave.final event. It examines the VTEntityDelta and <br>
if the "assigned_user_id" changes, it updates my new Previously Assigned <br>
To field with the old_value of the Delta using vtws_revise (to trigger <br>
the new workflow below). This is working - so on-screen when viewing the <br>
Lead, it shows the new Assigned To value and the Previously Assigned To <br>
field shows the old Assigned To value.<br>
<br>
I then created a Workflow for the Leads module to send an Email to the <br>
Previously Assigned To user, with a trigger when the Previously Assigned <br>
To field changes, to inform them that they no longer own this record.<br>
<br>
The workflow is triggered by the Event handler as I would expect. BUT <br>
this workflow retrieves the older value of the Previously Assigned To <br>
field (yet it has the right Assigned To value). So it sends the email to <br>
the previously Previously Assigned To ;-)<br>
<br>
<br>
Here's the relevant Event Handler code:<br>
<br>
> if($handlerType == 'vtiger.entity.aftersave.final' && in_array($moduleName, $modules)) {<br>
> // Use Admin user so we can make the field Read Only in profiles<br>
> $user = Users::getActiveAdminUser();<br>
> $recordId = $entityData->getId();<br>
> $vtEntityDelta = new VTEntityDelta();<br>
> $prevAssTo = $vtEntityDelta->getOldValue($moduleName, $recordId, 'assigned_user_id');<br>
> if($prevAssTo) {<br>
> $prevAssTo = vtws_getWebserviceEntityId('Users', $prevAssTo);<br>
> try {<br>
> $wsid = vtws_getWebserviceEntityId($moduleName, $recordId);<br>
> $data = array('prev_assigned_to' => $prevAssTo, 'id' => $wsid);<br>
> $ent = vtws_revise($data, $user);<br>
> } catch (WebServiceException $ex) {<br>
> $log->debug($ex->getMessage());<br>
> }<br>
> }<br>
> }<br>
> $log->debug("Exiting Event Handler class: " . __CLASS__);<br>
<br>
What is wrong? How can I get the timing right?<br>
<br>
TIA<br>
<br>
Al<br>
_______________________________________________<br>
<a href="http://www.vtiger.com/" rel="noreferrer" target="_blank">http://www.vtiger.com/</a></blockquote></div>