hungrykoala
hungrykoala

Reputation: 1083

SugarCRM v6.5 How to get the field from another module and display it into a different module?

I know about the relationship but they only get the primary field, not the other fields. For example, I have two modules, module 1 holds the personal information of the user while module 2 let us say holds the person's activities. in module 2 I would like to display the gender base on his information from module 1.

How can I proceed with this?

Upvotes: 0

Views: 597

Answers (1)

Sachin I
Sachin I

Reputation: 1508

Please follow below steps to achieve this: Note: Make sure the Module-1 and Module-2 has one of the relationship 1-M or M-M

  • Step-1: Create new field in Module-2 to store/display the gender values

  • Step-2: Create new file in Module-2 location(custom/modules/Module2/views/view.detail.php)

 <?php
    require_once('include/MVC/View/views/view.detail.php');
    class Module2ViewDetail extends ViewDetail {

        function Module2ViewDetail() {
            parent::ViewDetail();
        }

      function display() {

            $recordId = $this->bean->id;
            global $db;
              if($recordId){
                  /* write a query to fetch gender($gender) from module */
              }
          $this->dv->process();

          $this->ss->assign('GENDER',$gender);
          echo $this->dv->display(); 
        }

    }

 ?>
  • Step 3: \custom\modules\Module2\metadata\detailviewdefs.php

Add the customCode in the gender field which you have created in Module2 like below. (Please note: Give the name of field similar to you custom field name):

 1 => 
     array (
     0 => 
       array (
          'name' => 'gender_c',
          'label' => 'LBL_GENDER',
          'customCode' => '{$GENDER}',
       ),
     1 => '',
),

Hope this will help you. Thanks!

Upvotes: 2

Related Questions