From 979b2491539871c69e5e594ef6d7297f73825535 Mon Sep 17 00:00:00 2001 From: colemanw Date: Tue, 11 Jul 2023 21:51:35 -0400 Subject: [PATCH] SearchKit - Ensure tasks are loaded when used as links --- .../traits/searchDisplayTasksTrait.service.js | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/ext/search_kit/ang/crmSearchTasks/traits/searchDisplayTasksTrait.service.js b/ext/search_kit/ang/crmSearchTasks/traits/searchDisplayTasksTrait.service.js index 05e5d926c3..d70e3357b7 100644 --- a/ext/search_kit/ang/crmSearchTasks/traits/searchDisplayTasksTrait.service.js +++ b/ext/search_kit/ang/crmSearchTasks/traits/searchDisplayTasksTrait.service.js @@ -14,16 +14,19 @@ this.entityInfo = null; this.getMetadata = function() { - if (fetchedMetadata) { - return; + if (!fetchedMetadata) { + fetchedMetadata = crmApi4({ + entityInfo: ['Entity', 'get', {select: ['name', 'title', 'title_plural', 'primary_key'], where: [['name', '=', mngr.getEntityName()]]}, 0], + tasks: ['SearchDisplay', 'getSearchTasks', {savedSearch: displayCtrl.search, display: displayCtrl.display}] + }).then(function(result) { + mngr.entityInfo = result.entityInfo; + mngr.tasks = result.tasks; + }, function(failure) { + mngr.tasks = []; + mngr.entityInfo = []; + }); } - fetchedMetadata = crmApi4({ - entityInfo: ['Entity', 'get', {select: ['name', 'title', 'title_plural', 'primary_key'], where: [['name', '=', mngr.getEntityName()]]}, 0], - tasks: ['SearchDisplay', 'getSearchTasks', {savedSearch: displayCtrl.search, display: displayCtrl.display}] - }).then(function(result) { - mngr.entityInfo = result.entityInfo; - mngr.tasks = result.tasks; - }); + return fetchedMetadata; }; this.getEntityName = function() { @@ -186,8 +189,11 @@ // If link is to a task rather than an ordinary href, run the task onClickLink: function(link, id, event) { if (link.task) { + const mngr = this.taskManager; event.preventDefault(); - this.taskManager.doTask(_.extend({title: link.title}, link.task), [id]); + mngr.getMetadata().then(function() { + mngr.doTask(_.extend({title: link.title}, link.task), [id]); + }); } }, -- 2.25.1