How set a value as selected on relate field

Hi All,

How to set the relate field value as selected , based on the value of a field on same module or another module ?

Please help me to find  a solution.

Parents Reply Children
  • If you are creating B from a subpanel on record A you should be able to get the data for ModuleA using the context:

    var parent_model = this.context.parent.get('model');

    That model contains the parent id and the module IF you started from a subpanel on ModuleA when you were creating B. If you create directly from the B module then we don't know what A is and the parent_model will be empty. 

    parent_model.get('id'); // will return the id of A record
    parent_model.get('_module'); // will return the name of the A module

    You can now get RL1 from A using parent_model.get('RL1') and copy it to RL2.

    If you want to set RL2 when B is related to A regardless of where you are starting from, then you can use an after_relate logic hook. There you can retrieve the beans for both sides of the relationship and copy the relate field from A to B.

    Be careful with the logic hook because it will override any other value you have in RL2 unless you put checks in place.

    I hope this answers your question.

    Francesca