From 065ce9b4742a75cf7f7586036174e7633cd1fc0c Mon Sep 17 00:00:00 2001
From: Uma <uma.s@vtiger.com>
Date: Wed, 25 Nov 2020 12:28:22 +0530
Subject: [PATCH] Cleanup handled on buildSearchQueryForFieldTypes api

---
 data/CRMEntity.php | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/data/CRMEntity.php b/data/CRMEntity.php
index 2ff6a3c47..40240010c 100644
--- a/data/CRMEntity.php
+++ b/data/CRMEntity.php
@@ -2653,12 +2653,20 @@ class CRMEntity {
 			}
 		}
 
+                $query = "select crmid as id ";
 		$entityfields = getEntityField($module);
 		$querycolumnnames = implode(',', $lookupcolumns);
 		$entitycolumnnames = $entityfields['fieldname'];
-		$query = "select crmid as id, $querycolumnnames, $entitycolumnnames as name ";
+                $log->fatal('$entitycolumnnames');
+                $log->fatal($entitycolumnnames);
+                if(!empty($querycolumnnames)){
+                    $query .= ", $querycolumnnames";
+                }
+                if(!empty($entitycolumnnames)){
+                    $query .= ", $entitycolumnnames as name ";
+                }
 		$query .= " FROM $this->table_name ";
-		$query .=" INNER JOIN vtiger_crmentity ON $this->table_name.$this->table_index = vtiger_crmentity.crmid AND deleted = 0 ";
+		$query .= " INNER JOIN vtiger_crmentity ON $this->table_name.$this->table_index = vtiger_crmentity.crmid AND deleted = 0 ";
 
 		//remove the base table
 		$LookupTable = array_unique($lookuptables);
-- 
GitLab