Menu
SuiteCRM Pull Request Party hosted by SalesAgility
Welcome, Guest
Username: Password: Remember me

TOPIC: Get advanced filter applied value

Get advanced filter applied value 5 months 6 days ago #76352

  • sagardundle
  • sagardundle's Avatar
  • Offline
  • New Member
  • Posts: 8
  • Thank you received: 1
  • Karma: 0
Hi,

i am trying to get advanced applied filter value "assigned username" in custom logic hook created for leads.
Based on that filter value i am going to show sum of amount according to assigned username.
Kindly help

Thanks,
Sagar
The administrator has disabled public write access.

Get advanced filter applied value 5 months 6 days ago #76364

  • pgr
  • pgr's Avatar
  • Offline
  • Administrator
  • Posts: 10196
  • Thank you received: 1531
  • Karma: 352
Sorry, I don't understand.

Which kind of logic hook is this?

Do you just need to know the "assigned user" name? Or what to do you need to do with it next?

And please always state your version of SuiteCRM.

My SuiteCRM In-depth blog.
Thank you for always stating your SuiteCRM version, checking your logs, reading the Docs, and searching before you ask!
The administrator has disabled public write access.

Get advanced filter applied value 5 months 6 days ago #76371

  • sagardundle
  • sagardundle's Avatar
  • Offline
  • New Member
  • Posts: 8
  • Thank you received: 1
  • Karma: 0
SUITECRM VERSION: 7.10.7, SUGAR VERSION: 6.5.25

i have created a logic hook for leads in following folder structure
\custom\modules\Leads\logic_hook.php
this file contains the following code:
$hook_array['after_ui_frame'][] = Array(1, 'Some description of what you are doing',     'custom/modules/Leads/SumfieldAmount__LogicHook.php','CustomAmountLead', 'functionToDisplayTheSumLead');

This logic hook calls SumfieldAmount__LogicHook.php file located in following path:
\custom\modules\Leads\logic_hook.php\SumfieldAmount__LogicHook.php

It contains the following code to find the sum of "oppurtunity amount" field in listview -
class CustomAmountLead {
           function functionToDisplayTheSumLead(&$focus, $event) {	
                if ($GLOBALS['action'] == 'index' || $GLOBALS['action'] == 'ListView') {
                        $yourSum = self::$yourSum; // TODO: maybe you want to add some formatting to numbers, dates, etc.
						global $db;

					//$id =  $this->bean->id;

					$query = "SELECT SUM(opportunity_amount) AS Amount FROM leads";

					$result = $db->query($query);

					$row = $db->fetchByAssoc($result);
					foreach($row as $value){
						
                        echo <<<EOHTML
<script type="text/javascript">
<!--
$('<td nowrap="nowrap" class="paginationActionButtons"><b>Grant Total: {$value}</b></td>').insertBefore('.paginationChangeButtons');
-->
</script>
EOHTML;
					} //end of foreach
                }
        } // end of functionToDisplayTheSum

} // end of YourPHPClassName
}


Now i get the following code run correctly to find the sum of opportunity amount in list view of leads.

But when i apply advanced filter i apply filter by "assigned username" so i need to get the sum of "opportunity amount" by assigned username. For Example:
if i apply advance filter in leads listview by "assigned username". I select sagar as as assigned username, then i should get the sum of "opportunity amount" of "sagar" in leads listview.
Last Edit: 5 months 5 days ago by pgr. Reason: add code tags
The administrator has disabled public write access.

Get advanced filter applied value 5 months 5 days ago #76391

  • pgr
  • pgr's Avatar
  • Offline
  • Administrator
  • Posts: 10196
  • Thank you received: 1531
  • Karma: 352
Ok, now I understand.

Are you using a debugger? If so, try looking at what session variables you have available at that point in the code. If you can find the data structures that describe the current filter, then you can work from there to add a "WHERE" clause to your SQL.

You might also want to check out this example, it's a different approach to a similar problem:
suitecrm.com/suitecrm/forum/developer-he...ay-total-lead-scores

My SuiteCRM In-depth blog.
Thank you for always stating your SuiteCRM version, checking your logs, reading the Docs, and searching before you ask!
The administrator has disabled public write access.

Get advanced filter applied value 5 months 5 days ago #76414

  • sagardundle
  • sagardundle's Avatar
  • Offline
  • New Member
  • Posts: 8
  • Thank you received: 1
  • Karma: 0
No, i am not using debugger. I am debugging using print_r() and exit.

I am trying to find the data structure of current filter but not able to get it.

I printed $bean and $focus but it all contains the leads listview array not the current filter data.

kindly help me
The administrator has disabled public write access.

Get advanced filter applied value 5 months 5 days ago #76416

  • sagardundle
  • sagardundle's Avatar
  • Offline
  • New Member
  • Posts: 8
  • Thank you received: 1
  • Karma: 0
The current filter is also not saved. If it was saved then i can get the data from database and query using where clause.
I googled a lot but could't got any solution to get data structure of current unsaved filter.

Please help me.
The administrator has disabled public write access.

Get advanced filter applied value 5 months 5 days ago #76447

  • pgr
  • pgr's Avatar
  • Offline
  • Administrator
  • Posts: 10196
  • Thank you received: 1531
  • Karma: 352
I would love to help you further, but I simply don't know.

Maybe the $_SESSION variables have something useful for you (REQUEST, etc).

Also try that other example I gave you, you might have access to other things in there. It's a different context, not a logic hook, so it's more tied in to the regular display of screens.

My SuiteCRM In-depth blog.
Thank you for always stating your SuiteCRM version, checking your logs, reading the Docs, and searching before you ask!
The administrator has disabled public write access.
The following user(s) said Thank You: sagardundle

Get advanced filter applied value 5 months 3 days ago #76577

  • sagardundle
  • sagardundle's Avatar
  • Offline
  • New Member
  • Posts: 8
  • Thank you received: 1
  • Karma: 0
Thanks,

It worked for me in logic hook itself using $_REQUEST;

When i print $_REQUEST in logic hook it displays all the advance filter data. Then i captured the 'assigned_user_id_advanced' and applied in where clause of logic hook query.


Thanks a lot
The administrator has disabled public write access.

Get advanced filter applied value 5 months 3 days ago #76581

  • pgr
  • pgr's Avatar
  • Offline
  • Administrator
  • Posts: 10196
  • Thank you received: 1531
  • Karma: 352
I'm glad to hear you got it working! B-)

Can you please share your code here? I'm sure it will help someone in the future... Thanks!

My SuiteCRM In-depth blog.
Thank you for always stating your SuiteCRM version, checking your logs, reading the Docs, and searching before you ask!
The administrator has disabled public write access.

Get advanced filter applied value 5 months 2 days ago #76609

  • sagardundle
  • sagardundle's Avatar
  • Offline
  • New Member
  • Posts: 8
  • Thank you received: 1
  • Karma: 0
Sure,

This is the logic hook file where i did changes

\custom\modules\Leads\logic_hook.php\SumfieldAmount__LogicHook.php

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

class CustomAmountLead {

        function functionToSumYourFieldLead(&$focus, $event) {

				global $assignedTo;
				if(!empty($_REQUEST['assigned_user_id_advanced'])){
				$assignedTo = $_REQUEST['assigned_user_id_advanced'];
				}
				//echo '<pre>'; print_r($_REQUEST);

               
        } // end of functionToSumYourField

        function functionToDisplayTheSumLead(&$bean, $event) {	
                if ($GLOBALS['action'] == 'index' || $GLOBALS['action'] == 'ListView') {
					global $db;
					global $assignedTo;	
					if(!empty($assignedTo)){
						foreach($assignedTo as $key => $value){
							$arr = $value;
						}
					}
					
				if(!empty($assignedTo)){
					$query = "SELECT SUM(opportunity_amount) AS Amount FROM leads ";
					$query .= "where assigned_user_id = '$arr'";
					$result = $db->query($query);
					$row = $db->fetchByAssoc($result);
					foreach($row as $value){
                        echo <<<EOHTML
<script type="text/javascript">
<!--
$('<td nowrap="nowrap" class="paginationActionButtons"><b>Grant Total: {$value}</b></td>').insertBefore('.paginationChangeButtons');
-->
</script>
EOHTML;
					} //end of foreach
					}else{
						$query = "SELECT SUM(opportunity_amount) AS Amount FROM leads";
					$result = $db->query($query);

					$row = $db->fetchByAssoc($result);
					foreach($row as $value){
						
                        echo <<<EOHTML
<script type="text/javascript">
<!--
$('<td nowrap="nowrap" class="paginationActionButtons"><b>Grant Total: {$value}</b></td>').insertBefore('.paginationChangeButtons');
-->
</script>
EOHTML;
					} //end of foreach
						
					}
                }
        } // end of functionToDisplayTheSum

} // end of YourPHPClassName


?>


Thanks pgr :) :)
Last Edit: 5 months 5 hours ago by pgr. Reason: add code tags
The administrator has disabled public write access.
The following user(s) said Thank You: pgr
Time to create page: 0.056 seconds
Powered by Kunena Forum