diff --git a/data/CRMEntity.php b/data/CRMEntity.php
index 44358d5de8d39bfefb01724b66a645275c65f9e4..5d231a2f64034c44c65d8faba1cc0847b095d794 100644
--- a/data/CRMEntity.php
+++ b/data/CRMEntity.php
@@ -410,10 +410,10 @@ class CRMEntity {
 		global $adb;
 		$insertion_mode = $this->mode;
         $table_name = Vtiger_Util_Helper::validateStringForSql($table_name);
+		$tablekey = $this->tab_name_index[$table_name];
         
 		//Checkin whether an entry is already is present in the vtiger_table to update
 		if ($insertion_mode == 'edit') {
-			$tablekey = $this->tab_name_index[$table_name];
 			// Make selection on the primary key of the module table to check.
 			$check_query = "select $tablekey from $table_name where $tablekey=?";
 			$check_params = array($this->id);
@@ -3181,4 +3181,4 @@ class TrackableObject implements ArrayAccess, IteratorAggregate {
 	function getColumnFieldNames(){
 		return array_keys($this->storage);
 	}
-}
\ No newline at end of file
+}