07-05-2017, 08:21 AM
A copy/paste from a Gitter discussion that might be usefull:
@Luke1982
09:13
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.
@Luke1982
09:22
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.
@joebordes
09:33
I would recommend an event handler
Instead of a workflow
coreBOS.link.after
(I think)
Or is it mandatory that it be a workflow?
@Luke1982
09:36
Would that event trigger after the full save script I created is done? Because basically, this is the save script: https://github.com/Luke1982/newSchedular...#L325-L381. 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.
@joebordes
09:44
Link event gets launched when the two records are related
Right before and after the insert in crmentityrel
@Luke1982
09:46
Ah OK, but only if you use vtlib I think? I place them into the DB directly.
@joebordes
09:46
https://github.com/tsolucio/corebos/blob...le.php#L50
yes, correct but that is easy to fix
@Luke1982
09:48
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
@joebordes
09:49
https://github.com/tsolucio/corebos/blob...ns.php#L40
Use related entities function
That has been there since May 2015
@Luke1982
09:51
That should be OK I think.
@Luke1982
10:10
One question
When corebos.entity.link.after 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?
@joebordes
10:12
Both
You get the name of both modules and both crmid
Look at the first link I pasted
In the coreboseventexample script
@Luke1982
10:14
You mean this: $entityData['destinationModule'].' '.$entityData['destinationRecordId']?
@joebordes
10:15
Yes
And the other two
source*
@Luke1982
10:17
So I could retrieve the linked module record through new $entityData['destinationModule'](); and then get the entity info through retrieve_entity_info()?
@joebordes
10:18
Sounds good
@Luke1982
09:13
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.
@Luke1982
09:22
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.
@joebordes
09:33
I would recommend an event handler
Instead of a workflow
coreBOS.link.after
(I think)
Or is it mandatory that it be a workflow?
@Luke1982
09:36
Would that event trigger after the full save script I created is done? Because basically, this is the save script: https://github.com/Luke1982/newSchedular...#L325-L381. 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.
@joebordes
09:44
Link event gets launched when the two records are related
Right before and after the insert in crmentityrel
@Luke1982
09:46
Ah OK, but only if you use vtlib I think? I place them into the DB directly.
@joebordes
09:46
https://github.com/tsolucio/corebos/blob...le.php#L50
yes, correct but that is easy to fix
@Luke1982
09:48
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
@joebordes
09:49
https://github.com/tsolucio/corebos/blob...ns.php#L40
Use related entities function
That has been there since May 2015
@Luke1982
09:51
That should be OK I think.
@Luke1982
10:10
One question
When corebos.entity.link.after 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?
@joebordes
10:12
Both
You get the name of both modules and both crmid
Look at the first link I pasted
In the coreboseventexample script
@Luke1982
10:14
You mean this: $entityData['destinationModule'].' '.$entityData['destinationRecordId']?
@joebordes
10:15
Yes
And the other two
source*
@Luke1982
10:17
So I could retrieve the linked module record through new $entityData['destinationModule'](); and then get the entity info through retrieve_entity_info()?
@joebordes
10:18
Sounds good