Hello,
I have two module. These are custom module. In the first module, I have m_name and ser_number. In the second module, I have ser_number but m_name is empty.
Now, I want to create a workflow which will update m_name in the 2nd module with m_name from the 1st module. The ser_number is matching condition between these two modules.
1st & 2nd modules does not have relationship defined in the CRM.
How can I achieve it? Do I have to create relationship first and then set condition.
I am trying this:
Basic:
Conditions:
Actions:
Retrieving a value for m_name via workflows seems to be only possible, if you have a relationship between those two modules.
With the relation in place, you can use calculated fields with a related parameter to copy the value. (at least in Suite7 - Iâve just tried it on multiple Suite8 installations, and there I donât see the related field).
Do you create the record in the 2nd module via a workflow triggered by the 1st?
Then you could copy that value during record creation.
Other than that, I only see a custom logic hook as another option (where youâd search for the ser_number in module 1 and load/save the value from there).
Thank you! I think the workflow is not a good option for this.
I have never used a logic hook. I want to try it out. ![:upside_down_face: :upside_down_face:](https://community.suitecrm.com/images/emoji/google/upside_down_face.png?v=12)
Why arenât you using a real relationship, instead of making one âmanuallyâ? if the two modules are linkedâŚ
What do you mean? Is there any other way to achieve this functionality?
![:thinking: :thinking:](https://community.suitecrm.com/images/emoji/google/thinking.png?v=12)
Is it correct? ![:upside_down_face: :upside_down_face:](https://community.suitecrm.com/images/emoji/google/upside_down_face.png?v=12)
- custom/Extension/modules/MODULE2/Ext/LogicHooks/update_m_name_logic_hook.php
- In the update_m_name_logic_hook.php file.
$hook_version = 1;
$hook_array = array();
$hook_array['after_save'] = array(
1,
'Update m_name in module1',
'custom/modules/MODULE2/update_m_name_logic.php',
'UpdateMNameLogic',
'updateMName'
);
- custom/modules/MODULE2/update_m_name_logic.php
- In the update_m_name_logic.php file.
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class UpdateMNameLogic
{
public function updateMName($bean, $event, $arguments)
{
if ($bean instanceof MODULE2) {
// Get ser_number and m_name from the saved bean
$ser_number = $bean->ser_number;
$m_name = $bean->m_name;
// Query module1 to find related records
$ieBean = BeanFactory::getBean('module1');
$ieBean->retrieve_by_string_fields(array('ser_number' => $ser_number));
// Check if module1 bean with matching ser_number is found
if (!empty($ieBean->id)) {
// Update m_name in module1
$ieBean->m_name = $m_name;
$ieBean->save();
}
}
}
}
Then QR&R
Overall it looks ok.
Did you run and debug it?
Compared to: Logic Hooks :: SuiteCRM Documentation
I see a few issues, which might not be any at all, if it works for you.
Youâve got a different folder than in the docsâŚ
$hook_array['before_save'] = Array();
seems to be missing?
'Update m_name in module1'
In PHP camelCase is often used - more cosmetics than an issue.
UpdateMName start with upper case U in the hook file and lower case in the class - youâve fixed that already?
Does your updateMName function work?
If you have issues there and an IDE / debugger / breakpoints, then this is a way to go.
Alternatively you can simply write some prints into a temporary local file for âdebuggingâ and seeing whatâs going on.
Yes, I ran it. It did not work for me. I was getting a blank page for the module and QRR. Then I tried to clear the cache directory and lost the admin dashboard; all pages were blank. It was a bad experience to run this logic hook ![:sweat_smile: :sweat_smile:](https://community.suitecrm.com/images/emoji/google/sweat_smile.png?v=12)
I got a MySQL query failed error in the log. I will share more details about the logic hook.
$GLOBALS[âlogâ]->fatal( ⌠sentence;
I am using this to get something into the log file.
Did you get it working already?
What happens, if you only do this one in the method body:
and write the ser_number to a log file?
And if that one works, continue step by step to uncomment the next lines of code.
Another idea to try, if you hard code the required number:
$ieBean->retrieve_by_string_fields(array('ser_number' => '123'));
By the way, the number is a string?
If itâs an integer, you might want to try the get_list method with a where query.
1 Like
It did not work for me. I think I need to use $hook_array[âbefore_saveâ] = Array(); as you suggested.
That is good idea. I need to check code in smaller pieces. ser_number is textField.