Workflow to update m_name field value based on ser_number


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:




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:

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? :face_with_peeking_eye: :thinking:

Is it correct? :upside_down_face:

  1. 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(
    'Update m_name in module1',

  1. 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;

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:

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.