calculate and display total lead scores

Hi everyone

i’m customizing lead module. in the photo bellow

I want to calculate total scores at the bottom and display result in lead score field at the top

How can I do, thanks

You can see an example here of customizing a detail view by extending the class and redefining the Display function:

https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/15154-is-there-logic-hook-for-detailsview#50990

You can do something similar for leads, and you can use some SQL to do the SUM and display it.

You can see an example of direct SQL access here

https://stackoverflow.com/questions/29781597/using-raw-sql-in-suitecrm

Please share your solution once you finish it. Thanks

2 Likes

Thank you for your suggestion.
So how can i push value in a field on database.

i’ve resolve it, but must reload 2 times
This is my code

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

require_once('include/MVC/View/views/view.detail.php');

class CustomLeadsViewDetail extends ViewDetail {
    
    public function display() {
        $this->_updateLeadScore();
        parent::display();
    }
    private function _updateLeadScore() {
            include_once 'data/SugarBean.php';

            $leadRecordId = $this->bean->id;
            $bean = new SugarBean();
            $query = "select sum(b.fs_score)as leadscore
            from leads_ldsco_fs_lead_score_1_c a
            inner join ldsco_fs_lead_score b
            on b.id = a.leads_ldsco_fs_lead_score_1ldsco_fs_lead_score_idb
            where a.leads_ldsco_fs_lead_score_1leads_ida = "."'".$leadRecordId."'"." and a.deleted =0";
	    $result = $bean->db->query($query,true," Error filling in additional detail fields: ");
	    $row = $bean->db->fetchByAssoc($result);
            
            $insert = "update leads_cstm
                        set fs_lead_score_c =".$row[leadscore]."
                        where id_c = "."'".$leadRecordId."'"."";

            if($row[leadscore] != null){
                $result = $bean->db->query($insert,true," Error filling in additional detail fields: ");
            } 

        }
}
2 Likes

That looks great, thanks for sharing!

Just one more detail for any users coming here in the future: where do you place that file, and what do you call it?

i place in custom/modules/Leads/views/view.detail.php

2 Likes