How to repopulate a related field by another one !

Dear all,

We’re customizing SuiteCRM to fit with our business. Can anyone help with below technical problem pls ?

[b]We have 2 enties: [Parent] & [Child].

On the CREATE screen, we also have 2 releated field [Parent] & [Child], now when user select one record on Parent we want the records on Child need to repopulate by Parent record. Please help me to do this. [/b]

Thanks,
HaiMM

Hello Haim,

Before I start to give you a possible solution and to get a bit more context, have you already start this feature with some approach?

Regards,

Thanks joaorpgomes.

My approach is developing a Custom Field Type for [Parent] which I can catch the event on it (onChange/onClick,…) then using ajax to call back-end to load data for [Child].

Can you give some ideas or other solution ?

Many Thanks,
HaiMM

Have a look here:
https://web.archive.org/web/20140116145925/http://www.eggsurplus.com/home/content/populate-a-dropdown-from-the-database/

2 Likes

Hello all,

Once you are using PHP I would recommend using the bean instance and not querying the database. I think it is more coherent and transparent when coding.

If your change is used on edit view, on the before_save hook, use BeanFactory to get the related bean you ned. then attribute it’s value to your new field. From this perspective maybe you do not need to expend time creating a new field type :wink:

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

Hope it helps

This is a hook that updates the parent record (Case) when user make changes to the child record (Client). I don’t know if this will help.


   class IncomeUpdateHook {
        public function updateIncome($focus, $event, $arguments) {
            $focus->personal_income = $focus->employer_wage + $focus->pension;
            $ori_value = $focus->fetched_row['personal_income'];
            $new_value = $focus->personal_income;
            if ($ori_value != $new_value) {
                $link = 'cases_cl_client_1';
                if ($focus->load_relationship($link)) {
                    $beans = $focus->$link->getBeans();
                    $bean = reset($beans);
                    $bean->household_income_c = $bean->household_income_c - $ori_value + $new_value;
                    $bean->save();
                }
            }
        }
    }

So you have that hook, in ParentModule, which when it’s updated will update your child’s field 'household_income_c ’ is that correct?

But now you need to bring that value to the parent Module. Is that right?

Sorry I am a bit loss here.

joaorpgomes, note that the person who posted that last bit of code was razgrizgt, who was just trying to help with a code sample, it wasn’t haimm (who made the original post). So yeah, this sometimes gets confusing :slight_smile:

1 Like