Limit rows dashlet in custom folder

hello friends is there any way to limit the number of rows in a dashlet but in the custom folder.

modules/Campaigns/Dashlets/TopCampaignsDashlet/TopCampaignsDashlet.php
to

custom/modules/Campaigns/Dashlets/TopCampaignsDashlet/TopCampaignsDashlet.php

$qry = "SELECT C.name AS campaign_name, SUM(O.amount) AS revenue, C.id as campaign_id " .
		   "FROM campaigns C, opportunities O " .
		   "WHERE C.id = O.campaign_id " . 
		   "AND O.sales_stage = 'Closed Won' " .
           "AND O.deleted = 0 " .
		   "GROUP BY C.name,C.id ORDER BY revenue desc";

	$result = $this->seedBean->db->limitQuery($qry, 0, 1);
	$row = $this->seedBean->db->fetchByAssoc($result);

	while ($row != null){
		array_push($this->top_campaigns, $row);
		$row = $this->seedBean->db->fetchByAssoc($result);

Hey!

I’ve had a look and, oddly enough, I’m also not able to limit the query by making a Custom version of that Dashlet in the /custom/ folder

There must be something else that connects or protects this dashlet’s content that I’ve not yet found :confused:


However, it looks like you might be able to make an identical Custom Dashlet, but with the limit included, if that sounds like a solution for you?


ie:

Copy:
modules/Campaigns/Dashlets/TopCampaignsDashlet/TopCampaignsDashlet.php

to:
custom/modules/Campaigns/Dashlets/TopCampaignsDashlet/

and rename it, ie:
custom/modules/Campaigns/Dashlets/TopCampaignsDashlet/LimitTopCampaignsDashlet.php

and update the Class name on line 49 accordingly in this new custom file,
image

(and feel free to change the query limit):
image


Then do the same for the metadata file:

Copy:
modules/Campaigns/Dashlets/TopCampaignsDashlet/TopCampaignsDashlet.meta.php

to:
custom/modules/Campaigns/Dashlets/TopCampaignsDashlet

and rename it similarly, ie:
custom/modules/Campaigns/Dashlets/TopCampaignsDashlet/limitTopCampaignsDashlet.meta.php


In this new xxxx.meta.php file, make some changes to differentiate it from the core Top Campaigns.

ie, I’ve changed the content of the file to the below:

global $app_strings;

$dashletMeta['limitTopCampaignsDashlet'] = array('module'		=> 'Campaigns',
                                               'title'     => translate('LBL_LIMIT_TOP_CAMPAIGNS', 'Campaigns'),
                                               'description' => translate('LBL_LIMIT_TOP_CAMPAIGNS_DESCRIPTION', 'Campaigns'),
                                               'category'    => 'Module Views');

(This changes the dashletMeta link as well as the two labels used)


Then, create a file at:
custom/modules/Campaigns/language/en_us.lang.php

And add these two language files, ie:

<?php
$mod_strings['LBL_LIMIT_TOP_CAMPAIGNS'] = 'Limited Top Campaigns';
$mod_strings['LBL_LIMIT_TOP_CAMPAIGNS_DESCRIPTION'] = 'Limited Top Campaigns';



After running a “Quick Repair and Rebuild” and “Rebuild SuiteCRM Dashlets”
You should see this new dashlet as an option on the Homepage, but let me know if you run into any issues!

From here, you should be able to make any changes you want to the query in the
“LimitTopCampaignsDashlet.php” file, (including limiting to one result), which then should be reflected in the CRM


Hopefully something like the above can help at all!

hi john,
it works perfectly, thanks
regards

1 Like

Glad to hear it!
Thanks for letting us know!