HowTo : customize related listview

Post vtiger CRM 5.4.0 help questions.
Bug Tracker|Image Installation|ImageWebmail

HowTo : customize related listview

Postby Tugami » Wed Aug 29, 2012 8:55 am

Hello,

After more research and post in the forum I finally found how to change the related list.
See my post : viewtopic.php?f=139&t=54684

An example: You want to modify the list of Trouble Tickets in Organization and add fields CreatedTime. problem, the column appears with no value !!!

Step 1: Determine what files to edit: modules/HelpDesk.php and modules/Accounts.php in our case.

Step 2: In the file for listview, here HepDesk.php, add the fields you want to see.
Change variables list_fields and list_fields_name. (lines 38 and 50)
Be careful: If you add a data from another table (cf_xxx) you have to add it in variables tab_name and tab_name_index (lines 25 and 26)

var $list_fields = Array(
    //Module Sequence Numbering
    //'Ticket ID'=>Array('crmentity'=>'crmid'),
    'Ticket No'=>Array('troubletickets'=>'ticket_no'),
    // END
    'Subject'=>Array('troubletickets'=>'title'),
    'Related to'=>Array('troubletickets'=>'parent_id'),
    'Status'=>Array('troubletickets'=>'status'),
    'Priority'=>Array('troubletickets'=>'priority'),
    'Created Time'=>Array('crmentity','createdtime'),
    'Assigned To'=>Array('crmentity','smownerid')
);
var $list_fields_name = Array(
    'Ticket No'=>'ticket_no',
    'Subject'=>'ticket_title',
    'Related to'=>'parent_id',
    'Status'=>'ticketstatus',
    'Priority'=>'ticketpriorities',
    'Created Time'=>'createdtime',
    'Assigned To'=>'assigned_user_id'
);


Step 3: In the module file here Accounts.php, modify the SQL query that retrieves the values.
To modify this function search term function begin by function get_,here function get_tickets
In this function search GetRelatedList, before this line you have the query.
Modify the sql query to add the fields, here createdtime

    /**
    * Function to get Account related Tickets
    * @param integer $id - accountid
    * returns related Ticket record in array format
    */
    function get_tickets($id, $cur_tab_id, $rel_tab_id, $actions=false) {
    .
    .
    .
    $query = "SELECT case when (vtiger_users.user_name not like '') then $userNameSql else vtiger_groups.groupname end as user_name, vtiger_users.id,
      vtiger_troubletickets.title, vtiger_troubletickets.ticketid AS crmid,
      vtiger_troubletickets.status, vtiger_troubletickets.priority,
      vtiger_troubletickets.parent_id, vtiger_troubletickets.ticket_no,
      vtiger_crmentity.smownerid, vtiger_crmentity.modifiedtime, vtiger_crmentity.createdtime
      FROM vtiger_troubletickets
      INNER JOIN vtiger_crmentity
      ON vtiger_crmentity.crmid = vtiger_troubletickets.ticketid
      LEFT JOIN vtiger_account
      ON vtiger_account.accountid = vtiger_troubletickets.parent_id
      LEFT JOIN vtiger_contactdetails
      ON vtiger_contactdetails.contactid=vtiger_troubletickets.parent_id
      LEFT JOIN vtiger_users
      ON vtiger_users.id=vtiger_crmentity.smownerid
      LEFT JOIN vtiger_groups
      ON vtiger_groups.groupid = vtiger_crmentity.smownerid
      WHERE vtiger_crmentity.deleted = 0 and vtiger_troubletickets.parent_id=$id" ;
    $return_value = GetRelatedList($this_module, $related_module, $other, $query, $button, $returnset);




Yes, it works!

Special Thanks to : dubwise
Best regards.

PS : Sorry for my bad english, I'm french and i use Google Translation Tool.
Tugami
 
Posts: 19
Joined: Thu May 10, 2012 9:48 am
Location: Saint Michel sur Meurthe, Vosges, FRANCE

Re: HowTo : customize related listview

Postby szabesz » Wed Aug 29, 2012 10:22 am

Thank you for the step-by-step guide! I will also give it a try sometime in the future. It would be good to have this customization feature built in vtiger, I hope it is in the dev's todo list ;)
szabesz
 
Posts: 44
Joined: Sun Aug 26, 2012 10:50 pm

Re: HowTo : customize related listview

Postby szabesz » Tue Sep 25, 2012 9:56 pm

Hi,

I have a custom module called "Brands" and (to edit the overriden function only) I have already copied the get_dependents_list function from CRMEntity.php to another related custom module called ProjectGroups.php. So far so good, but I just do not know how to extend the standard vtlib module SQL query ($query) to be able to fetch the brandsname field from the table vtiger_brands.

This standard query is this:
Code: Select all
$query = "SELECT vtiger_crmentity.*, $other->table_name.*";
         $userNameSql = getSqlForNameInDisplayFormat(array('first_name'=>'vtiger_users.first_name','last_name' => 'vtiger_users.last_name'), 'Users');
         $query .= ", CASE WHEN (vtiger_users.user_name NOT LIKE '') THEN $userNameSql ELSE vtiger_groups.groupname END AS user_name";
         $query .= ", vtiger_brands.brandsname AS brandsname ";
         $more_relation = '';
         if (!empty($other->related_tables)) {
            foreach ($other->related_tables as $tname => $relmap) {
               $query .= ", $tname.*";

               // Setup the default JOIN conditions if not specified
               if (empty($relmap[1]))
                  $relmap[1] = $other->table_name;
               if (empty($relmap[2]))
                  $relmap[2] = $relmap[0];
               $more_relation .= " LEFT JOIN $tname ON $tname.$relmap[0] = $relmap[1].$relmap[2]";
            }
         }

         $query .= " FROM $other->table_name";
         $query .= " INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = $other->table_name.$other->table_index";
         $query .= " INNER  JOIN $this->table_name   ON $this->table_name.$this->table_index = $other->table_name.$dependentColumn";
         $query .= $more_relation;
         $query .= " LEFT  JOIN vtiger_users        ON vtiger_users.id = vtiger_crmentity.smownerid";
         $query .= " LEFT  JOIN vtiger_groups       ON vtiger_groups.groupid = vtiger_crmentity.smownerid";

         $query .= " WHERE vtiger_crmentity.deleted = 0 AND $this->table_name.$this->table_index = $id";


And I need to include vtiger_brands.brandsname too.
Can anyone please tell me how to include it?

I hope I'm not missing anything else and this will enable the UI to display the related brandsname's value.

thanx in advance
Szabesz
szabesz
 
Posts: 44
Joined: Sun Aug 26, 2012 10:50 pm

Re: HowTo : customize related listview

Postby szabesz » Wed Sep 26, 2012 7:26 pm

Never mind, I've figured it out :)
szabesz
 
Posts: 44
Joined: Sun Aug 26, 2012 10:50 pm

Re: HowTo : customize related listview

Postby BernardGBailey » Tue Oct 09, 2012 7:51 pm

Hi szabesz,

What was it you figured out?

I am trying to add a field vtiger_details.cf_662 to the ListView in my details block. I have added the fields to the array and I am showing an empty column as you found.

I also cannot see where I need to add the field select.

Can you advise please.

Cheers
bernard
BernardGBailey
Senior Member
 
Posts: 267
Joined: Tue Dec 18, 2007 9:11 am
Location: Hamilton, New Zealand

Re: HowTo : customize related listview

Postby delsar » Fri Oct 12, 2012 4:12 am

Hello all

As you are on this section of the crm i thought you might be able to help me to change the sorting of callrelatedlist it is sorted default to "status" i want it as "crmid" any clues to where this is changed?

Thanks
Delsar
delsar
 
Posts: 1
Joined: Fri Oct 12, 2012 4:04 am

Re: HowTo : customize related listview

Postby Eric03 » Fri Feb 08, 2013 4:51 pm

I too am having issues getting fields that are cf_* to show up in related listviews. In particular the service contracts do not have a function in Accounts.php for retrieving them. There is a sql query in ServiceContracts.php but that does not appear to be retrieving the data either.
Eric03
 
Posts: 21
Joined: Mon Nov 26, 2012 8:27 pm


Return to Help - 5.4.0