Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to relate records the correct way and use event handlers on them
A copy/paste from a Gitter discussion that might be usefull:


Guys, I have a question. I'm creating a workflow that handles the first save of a Schedular record. I'd like this workflow to take into account the related module records I set in vtiger_crmentityrel. But those only get set AFTER I save the record for the first time, because I need the new record's ID. Now I'm thinking about using the value in vtiger_crmentity_seq to save the related records BEFORE I save the Schedular record. But the danger here is maybe that when multiple people are working in the CRM at the same time, this value could be wrong. But I'm not sure how PHP handles this. Are all other scripts blocked as long as I'm executing my script? Because then, I could use this value without the risk of it changing between setting the related modules and saving the record.

Hmm, reading into this I see I can write-lock the table and release that lock when I'm done. I think I'll give that a go.

I would recommend an event handler
Instead of a workflow
(I think)
Or is it mandatory that it be a workflow?

Would that event trigger after the full save script I created is done? Because basically, this is the save script: If the event handler triggers on the save method, I still would have no related records saved yet, because I have no ID to link them to.
No that is not a requirement per se.

Link event gets launched when the two records are related
Right before and after the insert in crmentityrel

Ah OK, but only if you use vtlib I think? I place them into the DB directly.

yes, correct but that is easy to fix

That's true. Do you have a hint where this method lives?
And when it was introduced? This module needs to work on an older installation

Use related entities function
That has been there since May 2015

That should be OK I think.

One question
When is fired, and the 'handleEvent' function receives the 'entityData' param, is that entity data the data of the LINKED module record, or the SOURCE module record?

You get the name of both modules and both crmid
Look at the first link I pasted
In the coreboseventexample script

You mean this: $entityData['destinationModule'].' '.$entityData['destinationRecordId']?

And the other two

So I could retrieve the linked module record through new $entityData['destinationModule'](); and then get the entity info through retrieve_entity_info()?

Sounds good

Forum Jump:

Users browsing this thread: 1 Guest(s)