Hi biztech,
Do you believe this solution will work for custom fields. As far as I know, it doesnāt.
On the other hand, this is a more elegant solution than using Logic Hooks, so I appreciate if you can tell me if it works for custom fields.
Thanks, Celso.
Hi, Celso, I followed your logic hooks steps but could not get it work. I would like to make sure my pre-condition is met for executing your code:
My scenario:
Pre-condition:
In my module A, I have a relate field for Module B (I do NOT create relationship between Module A and Module B, it is just a related field inserted in Module A)
What I try to do:
I try to auto fill/auto update a Drop Down field in Module A (of course, in Module B, there is an exact same drop down field.) So when I choose a record from Module B I would like to relate (using the relate field), I would like Drop down in Module A to display whatever is already saved in drop down value from Module B.
I am curious would data type matter, or affect the logic hooks? Does it work with drop down? Also, Can I match a currency data type to a integer datatype?
Inside your grabinfo function, I believe you could just access your fields directly from the $focus object, which corresponds do the SugarBean for the current record being processed under the Logic hook. Considering āquantity_of_Xā is a custom variable of your Module A record, you could just do this:
if (empty($focus->quantity_of_X)) {
...
}
When you do: ā$bean = BeanFactory::getBean(āJOBS_Jobsā, $focus->parent_id);ā, what do you want to do? This will try to retrieve a Bean of module named JOBS_Jobs with record ID ā$focus->parent_idā. But remember, āparent_idā must be a field from your Module A. This will happen whenever you have two modules with a formal relationship stablished. You āsaveā the record_id of a record on Module B into a field on a record on Module A.
I donāt see a way to relate two modules without really linking them using a relationship. But Iāve never did anything like this with custom modules.
Anyway, please try to explain me better what you want to do. Give details of your custom modules, the list of fields, etc., maybe we can try a solution.
Thank you so much, Celso!
You are right, without the formal relationship built between Module A & B, the method wonāt work.
As you suggested, I added the relationship, modified the code, got rid of the fetch_row and replaced the parent_id with the field name I try to retrieve and it works!
BTW, how could I grab two text fields data from Module B and store it in one field in Module A?
Also, I tried your method on retrieving related field from Module B, but it does not work. What should I do?
You can do almost anything you want, so I believe itās pretty easy to grab those fields from your Module B into a Module A record.
Since you have a record from module A related to module B, you could just try this in your LogicHook for ModuleA:
if (empty($focus->quantity_of_X)) {
// this will retrieve a record from ModuleB into $bean corresponding to the ID of the desired record in ModuleB
$bean = BeanFactory::getBean('ModuleB', $focus->variable_containing_id_of_moduleB); // $module, $record_id
if ($bean) { // test if $bean was loaded successfully
// this is only necessary if you'll need custom fields from ModuleB
$bean->custom_fields->retrieve();
// now set some variables of current record on ModuleA to values retrieved from the related record on ModuleB
$focus->variable1 = $bean->variable1;
$focus->variable2 = $bean->variable2;
}
}
Hello, Celso, Thank you again, just got the chance to test your latest code, it seems only working under if Module B is a āPARENTā of Module A, I mean, for example, module B has a one-to-many relationship w/ Module A, because, currently, I am trying to grab something from A and display to B, it is not working.
Itās working now!
Thank you again, Celso. I looked carefully through the PDF as you suggested and did some more research online.
Finally, I got it work, fetching the child record into a parent, so excited!
I need to add
reset() and current() two method to make it work. This is where I found the related info at https://community.sugarcrm.com/thread/18189
Hi Bruce!
Iām so glad you could solve your problem, congratulations!
These tricks like reset() and current() are similar to other situations like the need to āload custom fieldsā, when working with standard modules.
Those forums from SugarCRM are usually a good starting point for these tricks.
Anyway, the e-Book Iāve recommended you has so many useful information that youād waste several days to learn yourself, so I strongly suggest you buy that book.
Please donāt hesitate in contacting me if you need further assistance.
Sorry for not answering before.
Regards, Celso.
Celso, actually, I am still thinking to grab the field content from the related field module (not related module). I am wondering if I can find the related field id and put it in the beanFactory::getBean(ārelated field module nameā,ārelated field idā), after loading the bean, then i can access any field at that related field module and retrieve it. Will it work? I try to find the related field id in vardef, but could not locate it. :huh:
On the other hand, If that is not possible, going back to my previous success scenario, with the formal relationship built between my module A & B (many to many), but now A has 3 B records related to it, and I need to grab field content out of B records, put it back to A, if I use load_relationship method, and later, how to specify the different B in the code, which related records I am grabbing? :dry:
Hi Bruce,
Sorry for this long delay. I was out of sync regarding SuiteCRM for a couple of months.
Did you solve your problem? Please let me know about the details so that I can assist you.
Regards, Celso.
Many Thanks Celso! I did solve it eventually. Just played around with different logic hooks and tried to understand it thoroughly and finally fixed my problem.