Custom Module: get_list not working

I am currently trying to create a dropdown list based off a particular modules information. I am doing this by creating a logic hook for the module and using beans to get the list of information from the module.

When i do a get_list method on the ‘Accounts’ Module I am able to successfully pull back all accounts and needed information. When I attempt to do the same logic but using a custom module, the hook never completes and instead is on an infinite loop.

Any input would be greatly appreciated.


$roomsBean = BeanFactory::getBean('Accounts');

$roomsList = $roomsBean->get_full_list();

Are you sure it’s on an infinite loop? Are you writing stuff to the logs so you can check?

Which kind of hook is this? And is your hook doing anything else? If you save a bean on certain kinds of hooks that get called when a Bean is saved, you get infinite loops…

1 Like

It looks like an infinite loop. I am not writing anything to the logs, but i do have XDebug and am able to step through. The model gets returned correctly, but when it attempts the get_list function, it seems to repeat my logic_hook.php file. I checked the console for any error messages, but there are none.

My hook is very simple and it is not doing anything else(commented out everything else and this works with accountsBean).

My goal is to create a dropdown list that is generated by a query. The query is from another module and should return all rows of a particular column.

I am currently following the guide below, but it seems the folder structure of this guide might be outdated. I cannot find the directories that are referenced here.

Populate a Dropdown from the Database

Creating a logic hook seems like an appropriate way to get the data; however, I am very new to the development world of SuiteCRM. So it is very possible I am over looking something.

Thanks again for your input. Much appreciated.

Cool, using XDebug is much better than writing to logs!

You didn’t tell me which kind of hook it is (process_record, after_save, what?)

You might try a different method to get the list

https://docs.suitecrm.com/developer/working-with-beans/

maybe get_full_list or get_linked_beans or retrieve_by_string_fields, depending on what you can use to search. Try to see if you can get the Bean you want, and if the problem doesn’t arise with a different method.

I attempted get_list(), get_full_list(), get linked_bean(), retrieve_by_string_fields(). All failed. get_full_list and get_list were the only ones that caused the loop. The other two returned with 0 in the array.

As for the hook type, It will likely be best to have an ‘after_retrieve’ to give the user accurate data and ‘before_save’ to make sure theres no duplicate data.

I dont get why this isnt working. Ive looked at documentations and even a book, all say the get_list should work, but nothing references doing a get_list to a custom module. All references were with default modules. My understanding though sales the module extends the sugarBean class, which includes these functions. Since I am able to reference these function on the specific custom module bean, it doesnt make sense to me that this is not returning.

Is this even the right approach to get a dropdown that is based off of a query? Or is it better if I stay referencing that link on my first post?

If you post your FULL code and the files in which you inserted it, i t may be possible to test and try to help more!
Just two lines of code without all the rest is not sufficient to help!

Below is my current code. This is very basic, which is why I kept it very minimal previously. Keep in mind, I am trying to create a dropdown field which is generated by a query to a table within the suitecrm database.

Thanks again, I really do appreciate your time in help!

Created Files:

  1. custom/modules/as_Rooms/[color=#ff0044]logic_hooks.php[/color]
  2. custom/modules/as_Rooms/[color=#ff0044]logic_hooks_class.php[/color]

logic_hooks.php

<?php

$hook_version = 1;
$hook_array = Array();

$roomsBean = BeanFactory::getBean('as_Rooms');

$roomsList = $roomsBean->get_full_list();

$hook_array['after_retrieve'] = Array();
$hook_array['after_retrieve'][] = Array(
    //Processing index. For sorting the array.
    1,

    //Label. A string value to identify the hook.
    'after_retrieve example',

    //The PHP file where your class is located.
    'custom/modules/as_Rooms/logic_hooks_class.php',

    //The class the method is in.
    'logic_hooks_class',

    //The method to call.
    'after_retrieve_method'
);

log_hooks_class.php

<?php

if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class logic_hooks_class
{
    function after_retrieve_method($bean, $event, $arguments)
    {
        echo 'This is a TEST!!!';
    }
}

Try to add:

exit;

in the line immediately after:

 echo 'This is a TEST!!!';

Then Quick Repair and Rebuild and check if the code has been executed,

I noticed another thing.

You mention the file

logic_hooks_class.php

But when you pasted the contents of this file, you wrote:

log_hooks_class.php

(which is different than what it should be (“log_” instead of “logic_”, plus the rest))

But I assume that this is due to a typing error here in the forum.

Thanks. That was certainly a typo!

I tried to add the exit, but it doesnt even make it far enough to hit the retrieve method. Just keeps staying stuck on the get_full_list line. Everytime i try to continue the debug, it restarts the logic script and attempts to run the get_full_list function again repeatedly. It doesnt go past that line.

The answer is in your php_errors.log, or whatever your web server log is called…

Why do you have the two statements:

$roomsBean = BeanFactory::getBean('as_Rooms');

$roomsList = $roomsBean->get_full_list();

in the file: logic_hooks.php?

In this file you should only define the array for the logic hook, while in the other file you should put your logic.

These files are included in different moments of the execution flow so executing those statements at that moment may not be possible.

Additionally the logic hook itself is executed in a third part of the execution flow.

I think that you should stick to the flow and insert your logic in the class that you have defined and do what you want to do from there.

One more thing.

When you execute the following statement:

$roomsBean = BeanFactory::getBean('as_Rooms');

you assume that:

'as_Rooms'

is a valid (custom) module name.

You should verify if it actually is a valid module name.

Agreed. Typically these things would and should be separated. At this point, i am testing the logic in this location because I am still figuring out the proper structure for suitecrm custom modules.

I am able to make this call to another custom module I have, so although its not in its proper location, the call should be working. I also took a look at the php log file but did not find anytthing of relevance besides the typical notices you would get when running php.

I believe it has something to do with the module configuration. Not sure what exactly. I am currently testing a couple of scenarios and reverting my environment to have less records to test with. Maybe its a data issue?

this is actually correct. When I retrieve the bean, it is returned correctly with all its data. If you pass an invalid bean name to the getBean Method, it fails on that line and throws an error.

I have successfully created a dropdown however it does not seem to be populating. When I goto the module that is supposed to be loading the dropdown I get the following Warning:

getRoomNumbers i the function that I am trying to call which is supposed to return all of the data from the Database. This file is stored in the following location:

The vardef itself i stored in the following folder:

<?php

$dictionary['as_Rooms']['fields']['from_template_c'] = array (
'name' => 'from_template_c',
'vname' => 'LBL_FROM_TEMPLATE',
'function' => 'getRoomNumbers',
'type' => 'enum',
'len' => '100',
'comment' => 'The template that the project was created from.',
);

In our case we had a slowdown and after a bunch of troubleshooting it turned out to simply be a weak server… So before you spend too much time on this make sure you have enough ram. We figured out that the dev box had too little ram, by allocating 1gb everything started to fly.