How to display child module subpanel items in Primary module subpanel

Hi All,

I need to display the sub panel items of a child module in its parent module.

Imagine There are three modules Say A,B,C

1)  Many to one  relationship between the module A & B and Module B is a child module of A.

2) Many to one relationship between the module B & C . Module C is a child module of B and module C's items are displayed as a Subpanel in B.

I need to display the B's module subpanel for module C in Module A. That is module C as a sub panel in Module A.

Please advise me to find a solution for this.

  • You need to implement a LogicHook process_record to populate a non-db field in module A with the field from module B.

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hello André Lopes,

    Thank you,

    But actually I need to list the records of Module C in Module A.

    A -> B -> C are the three modules in hierarchical.

    I need to display module C records in the Sub panel of Module A. Please see the attached pic

  • You would need a function based subpanel, just like there are under Campaigns module, but unfortunately it is not sidecar compatible.

    So you should need to save on Module C records the id from Module A record on relating Module B records to a Module A record.

    This way you are able to render a regular Module C subpanel under Module A.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • Hi Thomas, 

    Can you describe a user case for have an example ? 

    I suppose, you can maybe deliver value with another way ...

  • Hello Sebastian,

    Imagine I have 3 Modules say A,B,C.

    Module B is a child Module of A.
    Module C is a child Module of B.

    And also I created a relationship Many to relationship between Module A and C,

    So Module C is also a Child module of A.

    My requirement is whenever creating a record in C under B.I need to list it under the module A too.

  • You need an after_relationship_add logic hook in C which when C is related to B finds the A related to B and relates A to C.

    so in module C you will have something like:

    class ModuleCLogic{
       function after_relationship_add($beanC, $event, $arguments){
          if($arguments['related_module'] == 'B'){
             //we just related C to B
             //find all the link names for the relationships and define them here
             $relBC = 'link_bc';
             $relAC = 'link_ac';
             $relAB = 'link_ab';
             //get bean B that you just related to C
             $beanB = BeanFactory::retrieveBean('B', $arguments['related_id']);
             //find the beans from module A related to the B you just related to C
             if($beanB->load_relationship($relAB)){
               //fetch the A beans related to B
               $beansA = $beanB->$relAB->getBeans();
               //you could have more than one $beansA in theory, depends on your relationship cardinality
                foreach($beansA as $beanA){
                   //relate A to C
                   if($beanA->load_relationship($relAC)){
                      $beanA->$relAC->add($beanC->id);
                   }
                }
             }
          }
       }
    }

     you will then need to add this function to the logic_hooks.php file in your module C

    Please note the code is not tested and written off the top of my head so take it with a pinch of salt.

    On a design note, you are creating a circular relationship with three points, you may have some other issues to contend with:

    what happens if you unlink B from C, should C also be unlinked from A?

    what if you link C to A directly, should C also be linked to all the Bs that are linked to A?

    what if you unlink B from A, should all the Cs linked to B also be removed from A?

    FrancescaS

  • Hello,

    May be you can try also to create a new subpanel with a relationship based on custom query to avoid data duplication : Creating Subpanels with Custom Results in Sugar 7.5