From 1d054d074c34065702de6d3c4076716c82db1f9b Mon Sep 17 00:00:00 2001
From: Uma <uma.s@vtiger.com>
Date: Thu, 9 Jul 2020 20:54:12 +0530
Subject: [PATCH] Fixes #1316 If inventory contact field is hidden address copy
 breaks

---
 languages/en_us/Vtiger.php                     |  6 ++++--
 layouts/v7/modules/Inventory/resources/Edit.js | 10 +++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/languages/en_us/Vtiger.php b/languages/en_us/Vtiger.php
index 4375a4632..6d0caecee 100644
--- a/languages/en_us/Vtiger.php
+++ b/languages/en_us/Vtiger.php
@@ -1936,6 +1936,8 @@ $jsLanguageStrings = array(
 	'JS_PASSWORD_MISMATCH_ERROR' => 'Please re-enter passwords. The "new password" and "confirm password" values do not match.',
 	'LBL_LIST_DELETE_CONFIRMATION' => 'Are you sure you want to delete?',
 	'JS_WIDGET_RESIZING_WAIT_MSG' => 'Widget contents will load after resizing.',
-    'JS_COPIED_SUCCESSFULLY' => 'Copied successfully',
-    'JS_ATLEAST_SELECT_ONE_FIELD' => 'At least one field should be selected',
+        'JS_COPIED_SUCCESSFULLY' => 'Copied successfully',
+        'JS_ATLEAST_SELECT_ONE_FIELD' => 'At least one field should be selected',
+        'JS_RELATED_ACCOUNT_IS_NOT_AVAILABLE' => 'Related Organization record is not available',
+        'JS_RELATED_CONTACT_IS_NOT_AVAILABLE' => 'Related Contact record is not available',
 );
diff --git a/layouts/v7/modules/Inventory/resources/Edit.js b/layouts/v7/modules/Inventory/resources/Edit.js
index 1f1f5abdb..d4952e72a 100644
--- a/layouts/v7/modules/Inventory/resources/Edit.js
+++ b/layouts/v7/modules/Inventory/resources/Edit.js
@@ -2576,6 +2576,10 @@ Vtiger_Edit_Js("Inventory_Edit_Js", {
 			var objectToMapAddress;
 			if(elementClass == "accountAddress"){
 				var recordRelativeAccountId = jQuery('[name="account_id"]').val();
+                                if(typeof recordRelativeAccountId == 'undefined'){
+                                    app.helper.showErrorNotification({'message':app.vtranslate('JS_RELATED_ACCOUNT_IS_NOT_AVAILABLE')});
+                                    return;
+                                }
 				if(recordRelativeAccountId == "" || recordRelativeAccountId == "0"){
 					app.helper.showErrorNotification({'message':app.vtranslate('JS_PLEASE_SELECT_AN_ACCOUNT_TO_COPY_ADDRESS')});
 				} else {
@@ -2595,8 +2599,12 @@ Vtiger_Edit_Js("Inventory_Edit_Js", {
 				}
 			}else if(elementClass == "contactAddress"){
 				var recordRelativeContactId = jQuery('[name="contact_id"]').val();
+                                if(typeof recordRelativeContactId == 'undefined'){
+                                    app.helper.showErrorNotification({'message':app.vtranslate('JS_RELATED_CONTACT_IS_NOT_AVAILABLE')});
+                                    return;
+                                }
 				if(recordRelativeContactId == "" || recordRelativeContactId == "0"){
-					app.helper.showErrorNotification({'message':app.vtranslate('JS_PLEASE_SELECT_AN_RELATED_TO_COPY_ADDRESS')});
+                                    app.helper.showErrorNotification({'message':app.vtranslate('JS_PLEASE_SELECT_AN_RELATED_TO_COPY_ADDRESS')});
 				} else {
 					var recordRelativeContactName = jQuery('#contact_id_display').val();
 					var editViewLabel = jQuery('#contact_id_display').closest('td');
-- 
GitLab