Iām relatively new to SuiteCRM and trying to figure out if something is possible and if so, how to do it. In the system Iām developing, I have added a module called āHospitalsā similar to Accounts that is related to Calls. Iāve been asked to add a field to the Calls module called āSignificant Contactā. Users will check that based on whatever criteria the project staff comes up with. All that is simple enough.
The next piece, however, is to display on the Hospital detail view the date of the most recent significant contact for that hospital. Basically, I need to get the max(date_start) from the calls table where calls_cstm.significant_contact_c = 1 for the particular hospital. Iāve found some code that looks similar to what I want to do, which is create a non-db field (i.e. most_recent_sig_contact) with the SQL necessary to get the appropriate value. What Iām not entirely sure of is where this code goes in my custom module and what, exactly, it needs to look like.
If anyone can provide an example of this or give me some pointers to this sort of thing in the docs, I would be much obliged.
Hello,
I think you should make a code in view.detail.php file. First get your expected result from query you used in your above comment.Here is some code sample which may help you.
- view.detail.php in custom directory of your custom module.
In display function.
// make a code to get your result
$query = āYour query should go hereā;
$date = $db->fetchByAssoc($db->query($query));
$maxDate = $date[ādate startā];
-
Then Assign this field like below
$this->dv->ss->assign(āmaxDateā, $maxDate);
// Assign this before parent display call.
-
Use this in detailviewdefs.php in custom
=>
array(
ānameā => āyour nondb fieldā,
ālabelā => āLBL_Lableā,
ācustomCodeā => ā{$maxDate}ā
),
Hope this will you.
Thanks.
Thanks. I think Iām getting close and this is very helpful.
One question I have is about the view.detail.php. That file did not already exist. I assumed I need to make one. I copied one from another module putting it in modules/hosp_Hospital/view/view.detail.php. Is that the right place for it? Then I edited it, removing everything except the __construct() and display() functions and changed the names to use āhosp_Hospitalā in place of the names that were there. I added your four lines to the display function, with the only other line in that function being āparent::display()ā at the end. Does that sound right?
The field is being displayed with the label I assigned but itās not being populated, so clearly Iāve done something wrong. It isnāt clear to me that the view.detail.php file that I created is actually being run or loaded. Do I need to do something so that it will be?
This will probably be obvious to others but isnāt to me: Should I create a field first, and then assign it this value or just modify the code without creating a field through any other means?
Hello there,
One question I have is about the view.detail.php. That file did not already exist. I assumed I need to make one. I copied one from another module putting it in modules/hosp_Hospital/view/view.detail.php. Is that the right place for it?
ā Yes because this is your own module so this can be right place but in SuiteCRM standard method is to put this in custom dir. but thatās ok.As I assumed your module name is āhosp_Hospitalā I have make a code sample for it. Just copy and paste into your view.detail.php and put your sql query into right place.
require_once(āinclude/MVC/View/views/view.detail.phpā);
class hosp_HospitalViewDetail extends ViewDetail {
function display() {
global $db;
// make a code to get your result
$query = "Your query should go here";
$runQ = $db->query($query);
$date = $db->fetchByAssoc($runQ);
$maxDate = $date;
$this->dv->ss->assign('maxDate', $maxDate);
parent::display();
}
}
And about non-db field if you have not created then please first create.rest please follow my recent post.
If still getting any doubts you can share your view.detail.php and detailviewdefs.php file.So I will make changes in that.
Thanks.
Once again, thank you. The code you just posted is pretty close to what I had. The only significant difference is that I hadnāt included the ārequire_onceā line. The bigger error, however, turns out to be where I put the file. I had this in a sub-directory called āviewā but it was supposed to be āviewsā (plural). Once I fixed that, the code actually ran. Thank you very much for your time and explanation.