diff --git a/ui/hosts.php b/ui/hosts.php
index 004a486e08..803b498de9 100644
--- a/ui/hosts.php
+++ b/ui/hosts.php
@@ -653,7 +653,9 @@ elseif (hasRequest('action') && getRequest('action') === 'host.massupdate' && ha
 		}
 		unset($host);
 
-		if (!API::Host()->update($hosts)) {
+		$result = $hosts ? (bool) API::Host()->update($hosts) : true;
+
+		if ($result === false) {
 			throw new Exception();
 		}
 
diff --git a/ui/include/classes/api/services/CApplication.php b/ui/include/classes/api/services/CApplication.php
index e5c5cb7d79..9e688c9be1 100644
--- a/ui/include/classes/api/services/CApplication.php
+++ b/ui/include/classes/api/services/CApplication.php
@@ -662,18 +662,25 @@ class CApplication extends CApiService {
 
 		// adding items
 		if ($options['selectItems'] !== null && $options['selectItems'] != API_OUTPUT_COUNT) {
+			$items = [];
 			$relationMap = $this->createRelationMap($result, 'applicationid', 'itemid', 'items_applications');
-			$items = API::Item()->get([
-				'output' => $options['selectItems'],
-				'itemids' => $relationMap->getRelatedIds(),
-				'nopermissions' => true,
-				'preservekeys' => true
-			]);
+			$related_ids = $relationMap->getRelatedIds();
+
+			if ($related_ids) {
+				$items = API::Item()->get([
+					'output' => $options['selectItems'],
+					'itemids' => $related_ids,
+					'nopermissions' => true,
+					'preservekeys' => true
+				]);
+			}
+
 			$result = $relationMap->mapMany($result, $items, 'items');
 		}
 
 		// adding discovery rule
 		if ($options['selectDiscoveryRule'] !== null && $options['selectDiscoveryRule'] != API_OUTPUT_COUNT) {
+			$discoveryRules = [];
 			$relationMap = new CRelationMap();
 
 			$dbRules = DBselect(
@@ -689,12 +696,16 @@ class CApplication extends CApiService {
 				$relationMap->addRelation($rule['applicationid'], $rule['itemid']);
 			}
 
-			$discoveryRules = API::DiscoveryRule()->get([
-				'output' => $options['selectDiscoveryRule'],
-				'itemids' => $relationMap->getRelatedIds(),
-				'nopermissions' => true,
-				'preservekeys' => true
-			]);
+			$related_ids = $relationMap->getRelatedIds();
+
+			if ($related_ids) {
+				$discoveryRules = API::DiscoveryRule()->get([
+					'output' => $options['selectDiscoveryRule'],
+					'itemids' => $related_ids,
+					'nopermissions' => true,
+					'preservekeys' => true
+				]);
+			}
 
 			$result = $relationMap->mapOne($result, $discoveryRules, 'discoveryRule');
 		}
diff --git a/ui/include/classes/api/services/CDashboardGeneral.php b/ui/include/classes/api/services/CDashboardGeneral.php
index 2591e95a6a..ca3ccec5c4 100644
--- a/ui/include/classes/api/services/CDashboardGeneral.php
+++ b/ui/include/classes/api/services/CDashboardGeneral.php
@@ -747,12 +747,17 @@ abstract class CDashboardGeneral extends CApiService {
 			// Adding user shares.
 			if ($options['selectUsers'] !== null) {
 				$relation_map = $this->createRelationMap($result, 'dashboardid', 'userid', 'dashboard_user');
-				// Get all allowed users.
-				$db_users = API::User()->get([
-					'output' => [],
-					'userids' => $relation_map->getRelatedIds(),
-					'preservekeys' => true
-				]);
+				$related_ids = $relation_map->getRelatedIds();
+				$db_users = [];
+
+				if ($related_ids) {
+					// Get all allowed users.
+					$db_users = API::User()->get([
+						'output' => [],
+						'userids' => $related_ids,
+						'preservekeys' => true
+					]);
+				}
 
 				if ($db_users) {
 					$db_dashboard_users = API::getApiService()->select('dashboard_user', [
@@ -784,12 +789,17 @@ abstract class CDashboardGeneral extends CApiService {
 			// Adding user group shares.
 			if ($options['selectUserGroups'] !== null) {
 				$relation_map = $this->createRelationMap($result, 'dashboardid', 'usrgrpid', 'dashboard_usrgrp');
-				// Get all allowed groups.
-				$db_usrgrps = API::UserGroup()->get([
-					'output' => [],
-					'usrgrpids' => $relation_map->getRelatedIds(),
-					'preservekeys' => true
-				]);
+				$related_ids = $relation_map->getRelatedIds();
+				$db_usrgrps = [];
+
+				if ($related_ids) {
+					// Get all allowed groups.
+					$db_usrgrps = API::UserGroup()->get([
+						'output' => [],
+						'usrgrpids' => $related_ids,
+						'preservekeys' => true
+					]);
+				}
 
 				if ($db_usrgrps) {
 					$db_dashboard_usrgrps = API::getApiService()->select('dashboard_usrgrp', [
diff --git a/ui/include/classes/api/services/CDiscoveryRule.php b/ui/include/classes/api/services/CDiscoveryRule.php
index 1c5e98b08c..438725da8a 100644
--- a/ui/include/classes/api/services/CDiscoveryRule.php
+++ b/ui/include/classes/api/services/CDiscoveryRule.php
@@ -2715,16 +2739,20 @@ class CDiscoveryRule extends CItemGeneral {
 
 		if ($options['selectApplicationPrototypes'] !== null
 				&& $options['selectApplicationPrototypes'] != API_OUTPUT_COUNT) {
+			$application_prototypes = [];
 			$relation_map = $this->createRelationMap($result, 'itemid', 'application_prototypeid',
 				'application_prototype'
 			);
+			$related_ids = $relation_map->getRelatedIds();
 
-			$application_prototypes = API::getApiService()->select('application_prototype', [
-				'output' => $options['selectApplicationPrototypes'],
-				'filter' => ['application_prototypeid' => $relation_map->getRelatedIds()],
-				'limit' => $options['limitSelects'],
-				'preservekeys' => true
-			]);
+			if ($related_ids) {
+				$application_prototypes = API::getApiService()->select('application_prototype', [
+					'output' => $options['selectApplicationPrototypes'],
+					'application_prototypeids' => $related_ids,
+					'limit' => $options['limitSelects'],
+					'preservekeys' => true
+				]);
+			}
 
 			$result = $relation_map->mapMany($result, $application_prototypes, 'applicationPrototypes',
 				$options['limitSelects']
@@ -2901,156 +2929,160 @@ class CDiscoveryRule extends CItemGeneral {
 				unset($override);
 			}
 
-			if ($operations_requested) {
-				$operations = API::getApiService()->select('lld_override_operation', [
+			if ($operations_requested && $overrides) {
+				$operations = DB::select('lld_override_operation', [
 					'output' => ['lld_override_operationid', 'lld_overrideid', 'operationobject', 'operator', 'value'],
 					'filter' => ['lld_overrideid' => array_keys($overrides)],
-					'sortfield' => 'lld_override_operationid',
+					'sortfield' => ['lld_override_operationid'],
 					'preservekeys' => true
 				]);
 
-				$opdiscover = DB::select('lld_override_opdiscover', [
-					'output' => ['lld_override_operationid', 'discover'],
-					'filter' => ['lld_override_operationid' => array_keys($operations)]
-				]);
+				if ($operations) {
+					$opdiscover = DB::select('lld_override_opdiscover', [
+						'output' => ['lld_override_operationid', 'discover'],
+						'filter' => ['lld_override_operationid' => array_keys($operations)]
+					]);
 
-				$item_prototype_objectids = [];
-				$trigger_prototype_objectids = [];
-				$host_prototype_objectids = [];
+					$item_prototype_objectids = [];
+					$trigger_prototype_objectids = [];
+					$host_prototype_objectids = [];
 
-				foreach ($operations as $operation) {
-					switch ($operation['operationobject']) {
-						case OPERATION_OBJECT_ITEM_PROTOTYPE:
-							$item_prototype_objectids[$operation['lld_override_operationid']] = true;
-							break;
+					foreach ($operations as $operation) {
+						switch ($operation['operationobject']) {
+							case OPERATION_OBJECT_ITEM_PROTOTYPE:
+								$item_prototype_objectids[$operation['lld_override_operationid']] = true;
+								break;
 
-						case OPERATION_OBJECT_TRIGGER_PROTOTYPE:
-							$trigger_prototype_objectids[$operation['lld_override_operationid']] = true;
-							break;
+							case OPERATION_OBJECT_TRIGGER_PROTOTYPE:
+								$trigger_prototype_objectids[$operation['lld_override_operationid']] = true;
+								break;
 
-						case OPERATION_OBJECT_HOST_PROTOTYPE:
-							$host_prototype_objectids[$operation['lld_override_operationid']] = true;
-							break;
+							case OPERATION_OBJECT_HOST_PROTOTYPE:
+								$host_prototype_objectids[$operation['lld_override_operationid']] = true;
+								break;
+						}
 					}
-				}
 
-				if ($item_prototype_objectids || $trigger_prototype_objectids || $host_prototype_objectids) {
-					$opstatus = DB::select('lld_override_opstatus', [
-						'output' => ['lld_override_operationid', 'status'],
-						'filter' => ['lld_override_operationid' => array_keys(
-							$item_prototype_objectids + $trigger_prototype_objectids + $host_prototype_objectids
-						)]
-					]);
-				}
+					if ($item_prototype_objectids || $trigger_prototype_objectids || $host_prototype_objectids) {
+						$opstatus = DB::select('lld_override_opstatus', [
+							'output' => ['lld_override_operationid', 'status'],
+							'filter' => ['lld_override_operationid' => array_keys(
+								$item_prototype_objectids + $trigger_prototype_objectids + $host_prototype_objectids
+							)]
+						]);
+					}
 
-				if ($item_prototype_objectids) {
-					$ophistory = DB::select('lld_override_ophistory', [
-						'output' => ['lld_override_operationid', 'history'],
-						'filter' => ['lld_override_operationid' => array_keys($item_prototype_objectids)]
-					]);
-					$optrends = DB::select('lld_override_optrends', [
-						'output' => ['lld_override_operationid', 'trends'],
-						'filter' => ['lld_override_operationid' => array_keys($item_prototype_objectids)]
-					]);
-					$opperiod = DB::select('lld_override_opperiod', [
-						'output' => ['lld_override_operationid', 'delay'],
-						'filter' => ['lld_override_operationid' => array_keys($item_prototype_objectids)]
-					]);
-				}
+					if ($item_prototype_objectids) {
+						$ophistory = DB::select('lld_override_ophistory', [
+							'output' => ['lld_override_operationid', 'history'],
+							'filter' => ['lld_override_operationid' => array_keys($item_prototype_objectids)]
+						]);
+						$optrends = DB::select('lld_override_optrends', [
+							'output' => ['lld_override_operationid', 'trends'],
+							'filter' => ['lld_override_operationid' => array_keys($item_prototype_objectids)]
+						]);
+						$opperiod = DB::select('lld_override_opperiod', [
+							'output' => ['lld_override_operationid', 'delay'],
+							'filter' => ['lld_override_operationid' => array_keys($item_prototype_objectids)]
+						]);
+					}
 
-				if ($trigger_prototype_objectids) {
-					$opseverity = DB::select('lld_override_opseverity', [
-						'output' => ['lld_override_operationid', 'severity'],
-						'filter' => ['lld_override_operationid' => array_keys($trigger_prototype_objectids)]
-					]);
-				}
+					if ($trigger_prototype_objectids) {
+						$opseverity = DB::select('lld_override_opseverity', [
+							'output' => ['lld_override_operationid', 'severity'],
+							'filter' => ['lld_override_operationid' => array_keys($trigger_prototype_objectids)]
+						]);
+					}
 
-				if ($trigger_prototype_objectids || $host_prototype_objectids) {
-					$optag = DB::select('lld_override_optag', [
-						'output' => ['lld_override_operationid', 'tag', 'value'],
-						'filter' => ['lld_override_operationid' => array_keys(
-							$trigger_prototype_objectids + $host_prototype_objectids
-						)]
-					]);
-				}
+					if ($trigger_prototype_objectids || $host_prototype_objectids) {
+						$optag = DB::select('lld_override_optag', [
+							'output' => ['lld_override_operationid', 'tag', 'value'],
+							'filter' => ['lld_override_operationid' => array_keys(
+								$trigger_prototype_objectids + $host_prototype_objectids
+							)]
+						]);
+					}
 
-				if ($host_prototype_objectids) {
-					$optemplate = DB::select('lld_override_optemplate', [
-						'output' => ['lld_override_operationid', 'templateid'],
-						'filter' => ['lld_override_operationid' => array_keys($host_prototype_objectids)]
-					]);
-					$opinventory = DB::select('lld_override_opinventory', [
-						'output' => ['lld_override_operationid', 'inventory_mode'],
-						'filter' => ['lld_override_operationid' => array_keys($host_prototype_objectids)]
-					]);
-				}
+					if ($host_prototype_objectids) {
+						$optemplate = DB::select('lld_override_optemplate', [
+							'output' => ['lld_override_operationid', 'templateid'],
+							'filter' => ['lld_override_operationid' => array_keys($host_prototype_objectids)]
+						]);
+						$opinventory = DB::select('lld_override_opinventory', [
+							'output' => ['lld_override_operationid', 'inventory_mode'],
+							'filter' => ['lld_override_operationid' => array_keys($host_prototype_objectids)]
+						]);
+					}
 
-				foreach ($operations as &$operation) {
-					if ($item_prototype_objectids || $trigger_prototype_objectids || $host_prototype_objectids) {
-						foreach ($opstatus as $row) {
-							if (bccomp($operation['lld_override_operationid'], $row['lld_override_operationid']) == 0) {
-								$operation['opstatus']['status'] = $row['status'];
+					foreach ($operations as &$operation) {
+						$lld_override_operationid = $operation['lld_override_operationid'];
+
+						if ($item_prototype_objectids || $trigger_prototype_objectids || $host_prototype_objectids) {
+							foreach ($opstatus as $row) {
+								if (bccomp($lld_override_operationid, $row['lld_override_operationid']) == 0) {
+									$operation['opstatus']['status'] = $row['status'];
+								}
 							}
 						}
-					}
 
-					foreach ($opdiscover as $row) {
-						if (bccomp($operation['lld_override_operationid'], $row['lld_override_operationid']) == 0) {
-							$operation['opdiscover']['discover'] = $row['discover'];
+						foreach ($opdiscover as $row) {
+							if (bccomp($lld_override_operationid, $row['lld_override_operationid']) == 0) {
+								$operation['opdiscover']['discover'] = $row['discover'];
+							}
 						}
-					}
 
-					if ($item_prototype_objectids) {
-						foreach ($ophistory as $row) {
-							if (bccomp($operation['lld_override_operationid'], $row['lld_override_operationid']) == 0) {
-								$operation['ophistory']['history'] = $row['history'];
+						if ($item_prototype_objectids) {
+							foreach ($ophistory as $row) {
+								if (bccomp($lld_override_operationid, $row['lld_override_operationid']) == 0) {
+									$operation['ophistory']['history'] = $row['history'];
+								}
 							}
-						}
 
-						foreach ($optrends as $row) {
-							if (bccomp($operation['lld_override_operationid'], $row['lld_override_operationid']) == 0) {
-								$operation['optrends']['trends'] = $row['trends'];
+							foreach ($optrends as $row) {
+								if (bccomp($lld_override_operationid, $row['lld_override_operationid']) == 0) {
+									$operation['optrends']['trends'] = $row['trends'];
+								}
 							}
-						}
 
-						foreach ($opperiod as $row) {
-							if (bccomp($operation['lld_override_operationid'], $row['lld_override_operationid']) == 0) {
-								$operation['opperiod']['delay'] = $row['delay'];
+							foreach ($opperiod as $row) {
+								if (bccomp($lld_override_operationid, $row['lld_override_operationid']) == 0) {
+									$operation['opperiod']['delay'] = $row['delay'];
+								}
 							}
 						}
-					}
 
-					if ($trigger_prototype_objectids) {
-						foreach ($opseverity as $row) {
-							if (bccomp($operation['lld_override_operationid'], $row['lld_override_operationid']) == 0) {
-								$operation['opseverity']['severity'] = $row['severity'];
+						if ($trigger_prototype_objectids) {
+							foreach ($opseverity as $row) {
+								if (bccomp($lld_override_operationid, $row['lld_override_operationid']) == 0) {
+									$operation['opseverity']['severity'] = $row['severity'];
+								}
 							}
 						}
-					}
 
-					if ($trigger_prototype_objectids || $host_prototype_objectids) {
-						foreach ($optag as $row) {
-							if (bccomp($operation['lld_override_operationid'], $row['lld_override_operationid']) == 0) {
-								$operation['optag'][] = ['tag' => $row['tag'], 'value' => $row['value']];
+						if ($trigger_prototype_objectids || $host_prototype_objectids) {
+							foreach ($optag as $row) {
+								if (bccomp($lld_override_operationid, $row['lld_override_operationid']) == 0) {
+									$operation['optag'][] = ['tag' => $row['tag'], 'value' => $row['value']];
+								}
 							}
 						}
-					}
 
-					if ($host_prototype_objectids) {
-						foreach ($optemplate as $row) {
-							if (bccomp($operation['lld_override_operationid'], $row['lld_override_operationid']) == 0) {
-								$operation['optemplate'][] = ['templateid' => $row['templateid']];
+						if ($host_prototype_objectids) {
+							foreach ($optemplate as $row) {
+								if (bccomp($lld_override_operationid, $row['lld_override_operationid']) == 0) {
+									$operation['optemplate'][] = ['templateid' => $row['templateid']];
+								}
 							}
-						}
 
-						foreach ($opinventory as $row) {
-							if (bccomp($operation['lld_override_operationid'], $row['lld_override_operationid']) == 0) {
-								$operation['opinventory']['inventory_mode'] = $row['inventory_mode'];
+							foreach ($opinventory as $row) {
+								if (bccomp($lld_override_operationid, $row['lld_override_operationid']) == 0) {
+									$operation['opinventory']['inventory_mode'] = $row['inventory_mode'];
+								}
 							}
 						}
 					}
+					unset($operation);
 				}
-				unset($operation);
 
 				$relation_map = $this->createRelationMap($operations, 'lld_overrideid', 'lld_override_operationid');
 
diff --git a/ui/include/classes/api/services/CItem.php b/ui/include/classes/api/services/CItem.php
index 3e489aa954..85deb9b35e 100644
--- a/ui/include/classes/api/services/CItem.php
+++ b/ui/include/classes/api/services/CItem.php
@@ -1030,12 +1030,17 @@ class CItem extends CItemGeneral {
 
 		// adding applications
 		if ($options['selectApplications'] !== null && $options['selectApplications'] != API_OUTPUT_COUNT) {
+			$applications = [];
 			$relationMap = $this->createRelationMap($result, 'itemid', 'applicationid', 'items_applications');
-			$applications = API::Application()->get([
-				'output' => $options['selectApplications'],
-				'applicationids' => $relationMap->getRelatedIds(),
-				'preservekeys' => true
-			]);
+			$related_ids = $relationMap->getRelatedIds();
+
+			if ($related_ids) {
+				$applications = API::Application()->get([
+					'output' => $options['selectApplications'],
+					'applicationids' => $related_ids,
+					'preservekeys' => true
+				]);
+			}
 			$result = $relationMap->mapMany($result, $applications, 'applications');
 		}
 
diff --git a/ui/include/classes/api/services/CItemPrototype.php b/ui/include/classes/api/services/CItemPrototype.php
index a3892262ef..173fb2ddc6 100644
--- a/ui/include/classes/api/services/CItemPrototype.php
+++ b/ui/include/classes/api/services/CItemPrototype.php
@@ -1026,47 +1026,57 @@ class CItemPrototype extends CItemGeneral {
 
 		// adding applications
 		if ($options['selectApplications'] !== null && $options['selectApplications'] != API_OUTPUT_COUNT) {
+			$applications = [];
 			$relationMap = $this->createRelationMap($result, 'itemid', 'applicationid', 'items_applications');
-			$applications = API::Application()->get([
-				'output' => $options['selectApplications'],
-				'applicationids' => $relationMap->getRelatedIds(),
-				'preservekeys' => true
-			]);
+			$related_ids = $relationMap->getRelatedIds();
+
+			if ($related_ids) {
+				$applications = API::Application()->get([
+					'output' => $options['selectApplications'],
+					'applicationids' => $related_ids,
+					'preservekeys' => true
+				]);
+			}
+
 			$result = $relationMap->mapMany($result, $applications, 'applications');
 		}
 
 		// adding application prototypes
 		if ($options['selectApplicationPrototypes'] !== null
 				&& $options['selectApplicationPrototypes'] != API_OUTPUT_COUNT) {
-			$pkFieldId = $this->pk('application_prototype');
-			$outputFields = [
-				$pkFieldId => $this->fieldId($pkFieldId, 'ap')
-			];
-
-			if (is_array($options['selectApplicationPrototypes'])) {
-				foreach ($options['selectApplicationPrototypes'] as $field) {
-					if ($this->hasField($field, 'application_prototype')) {
-						$outputFields[$field] = $this->fieldId($field, 'ap');
-					}
-				}
-
-				$outputFields = implode(',', $outputFields);
-			}
-			else {
-				$outputFields = 'ap.*';
-			}
-
+			$application_prototypes = [];
 			$relationMap = $this->createRelationMap($result, 'itemid', 'application_prototypeid',
 				'item_application_prototype'
 			);
+			$related_ids = $relationMap->getRelatedIds();
 
-			$application_prototypes = DBfetchArray(DBselect(
-				'SELECT '.$outputFields.
-				' FROM application_prototype ap'.
-				' WHERE '.dbConditionInt('ap.application_prototypeid', $relationMap->getRelatedIds())
-			));
+			if ($related_ids) {
+				$pkFieldId = $this->pk('application_prototype');
+				$outputFields = [
+					$pkFieldId => $this->fieldId($pkFieldId, 'ap')
+				];
 
-			$application_prototypes = zbx_toHash($application_prototypes, 'application_prototypeid');
+				if (is_array($options['selectApplicationPrototypes'])) {
+					foreach ($options['selectApplicationPrototypes'] as $field) {
+						if ($this->hasField($field, 'application_prototype')) {
+							$outputFields[$field] = $this->fieldId($field, 'ap');
+						}
+					}
+
+					$outputFields = implode(',', $outputFields);
+				}
+				else {
+					$outputFields = 'ap.*';
+				}
+
+				$application_prototypes = DBfetchArray(DBselect(
+					'SELECT '.$outputFields.
+					' FROM application_prototype ap'.
+					' WHERE '.dbConditionInt('ap.application_prototypeid', $related_ids)
+				));
+
+				$application_prototypes = zbx_toHash($application_prototypes, 'application_prototypeid');
+			}
 
 			$result = $relationMap->mapMany($result, $application_prototypes, 'applicationPrototypes');
 		}
diff --git a/ui/include/classes/api/services/CScreen.php b/ui/include/classes/api/services/CScreen.php
index 8d9a4628d5..d4ba5ab523 100644
--- a/ui/include/classes/api/services/CScreen.php
+++ b/ui/include/classes/api/services/CScreen.php
@@ -1291,20 +1291,25 @@ class CScreen extends CApiService {
 
 		// Adding user shares.
 		if ($options['selectUsers'] !== null && $options['selectUsers'] != API_OUTPUT_COUNT) {
+			$userids = [];
 			$relation_map = $this->createRelationMap($result, 'screenid', 'userid', 'screen_user');
-			// Get all allowed users.
-			$related_users = API::User()->get([
-				'output' => ['userid'],
-				'userids' => $relation_map->getRelatedIds(),
-				'preservekeys' => true
-			]);
+			$related_ids = $relation_map->getRelatedIds();
 
-			$related_userids = zbx_objectValues($related_users, 'userid');
+			if ($related_ids) {
+				// Get all allowed users.
+				$users = API::User()->get([
+					'output' => ['userid'],
+					'userids' => $related_ids,
+					'preservekeys' => true
+				]);
+
+				$userids = zbx_objectValues($users, 'userid');
+			}
 
-			if ($related_userids) {
+			if ($userids) {
 				$users = API::getApiService()->select('screen_user', [
 					'output' => $this->outputExtend($options['selectUsers'], ['screenid', 'userid']),
-					'filter' => ['screenid' => $screenIds, 'userid' => $related_userids],
+					'filter' => ['screenid' => $screenIds, 'userid' => $userids],
 					'preservekeys' => true
 				]);
 
@@ -1331,20 +1336,25 @@ class CScreen extends CApiService {
 
 		// Adding user group shares.
 		if ($options['selectUserGroups'] !== null && $options['selectUserGroups'] != API_OUTPUT_COUNT) {
+			$groupids = [];
 			$relation_map = $this->createRelationMap($result, 'screenid', 'usrgrpid', 'screen_usrgrp');
-			// Get all allowed groups.
-			$related_groups = API::UserGroup()->get([
-				'output' => ['usrgrpid'],
-				'usrgrpids' => $relation_map->getRelatedIds(),
-				'preservekeys' => true
-			]);
+			$related_ids = $relation_map->getRelatedIds();
 
-			$related_groupids = zbx_objectValues($related_groups, 'usrgrpid');
+			if ($related_ids) {
+				// Get all allowed groups.
+				$groups = API::UserGroup()->get([
+					'output' => ['usrgrpid'],
+					'usrgrpids' => $related_ids,
+					'preservekeys' => true
+				]);
+
+				$groupids = zbx_objectValues($groups, 'usrgrpid');
+			}
 
-			if ($related_groupids) {
+			if ($groupids) {
 				$user_groups = API::getApiService()->select('screen_usrgrp', [
 					'output' => $this->outputExtend($options['selectUserGroups'], ['screenid', 'usrgrpid']),
-					'filter' => ['screenid' => $screenIds, 'usrgrpid' => $related_groupids],
+					'filter' => ['screenid' => $screenIds, 'usrgrpid' => $groupids],
 					'preservekeys' => true
 				]);
 
diff --git a/ui/include/classes/api/services/CScreenItem.php b/ui/include/classes/api/services/CScreenItem.php
index dec428daf1..620cb272a2 100644
--- a/ui/include/classes/api/services/CScreenItem.php
+++ b/ui/include/classes/api/services/CScreenItem.php
@@ -143,6 +143,10 @@ class CScreenItem extends CApiService {
 	 * @param array $screenItems
 	 */
 	protected function validateCreate(array $screenItems) {
+		if (!$screenItems) {
+			self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.'));
+		}
+
 		$screenItemDBfields = [
 			'screenid' => null,
 			'resourcetype' => null
@@ -176,11 +180,13 @@ class CScreenItem extends CApiService {
 			'preservekeys' => true
 		]);
 
-		$dbScreenItems = API::getApiService()->select($this->tableName(), [
-			'output' => ['screenitemid', 'screenid', 'x', 'y', 'rowspan', 'colspan'],
-			'filter' => ['screenid' => array_keys($dbScreens)],
-			'preservekeys' => true
-		]);
+		$dbScreenItems = $dbScreens
+			? DB::select($this->tableName(), [
+				'output' => ['screenitemid', 'screenid', 'x', 'y', 'rowspan', 'colspan'],
+				'filter' => ['screenid' => array_keys($dbScreens)],
+				'preservekeys' => true
+			])
+			: [];
 
 		$this->checkInput($screenItems, $dbScreenItems);
 		$this->checkDuplicateResourceInCell(array_merge($screenItems, $dbScreenItems), $dbScreens);
@@ -255,6 +261,10 @@ class CScreenItem extends CApiService {
 	 * @param array $screenItems
 	 */
 	protected function validateUpdate(array $screenItems) {
+		if (!$screenItems) {
+			self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.'));
+		}
+
 		$screenItemDBfields = [
 			'screenitemid' => null
 		];
@@ -277,13 +287,15 @@ class CScreenItem extends CApiService {
 			'preservekeys' => true
 		]);
 
-		$dbScreenItems = API::getApiService()->select($this->tableName(), [
-			'output' => ['screenitemid', 'screenid', 'x', 'y', 'rowspan', 'colspan', 'resourcetype', 'resourceid',
-				'style'
-			],
-			'filter' => ['screenid' => array_keys($dbScreens)],
-			'preservekeys' => true
-		]);
+		$dbScreenItems = $dbScreens
+			? DB::select($this->tableName(), [
+				'output' => ['screenitemid', 'screenid', 'x', 'y', 'rowspan', 'colspan', 'resourcetype', 'resourceid',
+					'style'
+				],
+				'filter' => ['screenid' => array_keys($dbScreens)],
+				'preservekeys' => true
+			])
+			: [];
 
 		$screenItems = $this->extendObjects($this->tableName(), $screenItems,
 			['screenid', 'x', 'y', 'rowspan', 'colspan', 'style']
