Add logic hook on global search

I want to add an if statement before searching that if the query string is available on my select sql statement then I will change the value of the query string based on the result. How can I implement this?

$sql = “SELECT name FROM table WHERE quote_id = ‘{$queryString}’”;
$name= $GLOBALS[‘db’]->getOne($sql);
$queryString = $name ? $name: $queryString;

Hi, welcome to the Community! :tada:

Can you please explain where this is coming from? Which screen, which module?

HI Thank you for your reply. Sorry I’m new to suite crm. I have this table that I think is not included on the module. This table have the ID that I want to search. Like so.

table: not included
id other_id
table:included
other_id

I still have no idea what you’re talking about… maybe you can try adding a few screenshots? :confused:

Hi
As per my understanding I am trying to help you .

Follow below steps for Creating Logic Hook and changing the value of Query String

  1. custom/Extension/application/Ext/LogicHooks/GlobalSearchLogicHook.php
<?php
if (!isset($hook_array) || !is_array($hook_array)) {
	$hook_array = array();
}
if (!isset($hook_array['after_ui_frame']) || !is_array($hook_array['after_ui_frame'])) {
	$hook_array['after_ui_frame'] = array();
}
$hook_array['after_ui_frame'][] = array(
  1, //Hook version
  'GlobalSearchLogicHook',  //Label
  'custom/include/GlobalSearchLogicHook/GlobalSearchLogicHook.php', //Include file
  'GlobalSearchLogicHook', //Class
  'GlobalSearchLogicHook' //Method
);
?>
  1. custom/include/GlobalSearchLogicHook/GlobalSearchLogicHook.php
<?php
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
class GlobalSearchLogicHook{
	function GlobalSearchLogicHook(){  
 
    	if($_REQUEST['action'] == 'UnifiedSearch' && $_REQUEST['module'] == 'Home' && $_REQUEST['custom'] != 'query'){
        	$randomNumber = rand();
       	 
        	$queryString = $_REQUEST['query_string']; // get query string
 
        	//check query string record is exist or not in table
        	$sql = "SELECT name FROM table WHERE quote_id = '{$queryString}'";
        	$name = $GLOBALS['db']->getOne($sql);
 
        	$queryString = $name ? $name: $queryString;
       	 
        	//assign query string to the js
        	echo "<script type='text/javascript'>var queryString = ".$queryString."</script>";
 
        	echo '<script type="text/javascript" src="custom/include/GlobalSearchLogicHook/GlobalSearchLogicHook.js?v='.$randomNumber.'"></script>';
    	}//end of if
	}//end of function
}//end of clas
3) custom/include/GlobalSearchLogicHook/GlobalSearchLogicHook.js
$( document ).ready(function() {
    //redirect to the result with updated query string
    window.location.href = "index.php?action=UnifiedSearch&module=Home&search_form=false&advanced=false&query_string="+queryString+"&custom=query";
});//end of function

I hope this help you

Hi Urvi,

I really appreciate the effort, from there I learn a bit of the logic hooks.

Thank you for appreciation.