{"id":26408,"date":"2021-01-13T13:36:33","date_gmt":"2021-01-13T13:36:33","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=26408"},"modified":"2021-01-14T04:23:03","modified_gmt":"2021-01-14T04:23:03","slug":"use-relevance-search-api-in-power-automate-canvas-app-part-1","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2021\/01\/use-relevance-search-api-in-power-automate-canvas-app-part-1\/","title":{"rendered":"Use Relevance Search API in Power Automate &#038; Canvas App &#8211; Part 1"},"content":{"rendered":"<h1>Introduction<\/h1>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/docs.microsoft.com\/en-us\/powerapps\/user\/relevance-search\" target=\"_blank\" rel=\"noopener noreferrer\">Relevance Search<\/a> has been there for a while in our Dynamics 365 CRM that provides access to exciting new search capabilities in the environment. However, before you use this feature, an administrator must enable relevance search in target environment. Using relevance search we can search across multiple tables\/entities, sorted by relevance.<\/p>\n<p style=\"text-align: justify;\">Let us say you are on call with your customer and you want to check what information (Contact, Leads, Opportunities, emails, etc.) about this customer you have in your CRM.<\/p>\n<p style=\"text-align: justify;\">In this situation, we can use the Relevance search feature which will search your customer across all the tables in the system and will show it in the result list.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/Relevance-search-feature.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26409 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/Relevance-search-feature.png\" alt=\"Relevance search feature\" width=\"960\" height=\"568\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/Relevance-search-feature.png 960w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/Relevance-search-feature-300x178.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/Relevance-search-feature-768x454.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/Relevance-search-feature-660x391.png 660w\" sizes=\"(max-width: 960px) 100vw, 960px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">In the above screenshot, we searched for \u2018Nancy\u2019 and it showed the search results which included contact and lead.<\/p>\n<p style=\"text-align: justify;\">You can use this feature inside your Dynamics 365 CRM environment but what if you want to use Relevance Search functionality in your external system, say a custom portal or any other external app or plugin or Power Automate or Canvas App?<\/p>\n<p style=\"text-align: justify;\">Here the <a href=\"https:\/\/docs.microsoft.com\/en-us\/powerapps\/developer\/data-platform\/webapi\/relevance-search\" target=\"_blank\" rel=\"noopener noreferrer\">Relevance Search API<\/a> comes into the picture. We can use this API provided by Microsoft to add a relevance search feature to your project.<\/p>\n<p>POST [Organization URI]\/api\/search\/v1.0\/query<br \/>\n{<br \/>\n\u201csearch\u201d: \u201c&lt;search term&gt;\u201d<br \/>\n}<\/p>\n<p style=\"text-align: justify;\">This blog will illustrate how we can use the Relevance Search API to add the Relevance search feature into the Canvas app.<\/p>\n<p style=\"text-align: justify;\">I am dividing this blog into two parts. In the first part, we will create a Power Automate Flow to execute the Relevance Search API and in the second part, we will design a simple Canvas app then we will call the Power Automate flow to show the search results.<\/p>\n<p style=\"text-align: justify;\">Let us start with creating a Power Automate Flow that can be call from the Canvas App.<\/p>\n<p>\u2022 Create new Instant cloud Flow and select the PowerApps trigger.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/instant-flow-cloud.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26410 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/instant-flow-cloud.png\" alt=\"https:\/\/docs.microsoft.com\/en-us\/powerapps\/developer\/data-platform\/webapi\/relevance-search\" width=\"547\" height=\"397\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/instant-flow-cloud.png 547w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/instant-flow-cloud-300x218.png 300w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/a><\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-26411\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/power-apps.png\" alt=\"power apps\" width=\"945\" height=\"594\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/power-apps.png 945w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/power-apps-300x189.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/power-apps-768x483.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/power-apps-660x415.png 660w\" sizes=\"(max-width: 945px) 100vw, 945px\" \/><\/p>\n<p>\u2022 This will create a Power Automate Flow, which we can later call from the Canvas App. Give an appropriate name to the Flow.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/powerapps.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26413 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/powerapps.png\" alt=\"powerapps\" width=\"968\" height=\"287\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/powerapps.png 968w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/powerapps-300x89.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/powerapps-768x228.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/powerapps-660x196.png 660w\" sizes=\"(max-width: 968px) 100vw, 968px\" \/><\/a><\/p>\n<p>\u2022 Add the next step to initialize the variable and assign the text that the user wants to search for across the multiple tables.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/initializing-variable.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26415 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/initializing-variable.png\" alt=\"initialize variable\" width=\"638\" height=\"474\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/initializing-variable.png 638w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/initializing-variable-300x223.png 300w\" sizes=\"(max-width: 638px) 100vw, 638px\" \/><\/a><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-26430 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/ask-in-powerapps.png\" alt=\"ask in power apps\" width=\"817\" height=\"443\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/ask-in-powerapps.png 817w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/ask-in-powerapps-300x163.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/ask-in-powerapps-768x416.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/ask-in-powerapps-660x358.png 660w\" sizes=\"(max-width: 817px) 100vw, 817px\" \/><\/p>\n<p>\u2022 To execute the Relevance search API, we first need to get the Access Token to authenticate the request. To do this we will use HTTP Request action.<\/p>\n<p>Add new Step in the flow and select the HTTP request.<\/p>\n<p style=\"text-align: justify;\">In this step, we are obtaining the access token that can be used to execute the Relevance Search API request.<\/p>\n<p>Here we are using the Application User, which is a non-licensed user to generate the Access token.<br \/>\nAs a prerequisite, you must perform the below,<br \/>\n&#8211; First, we have to register an Application on the Azure Active Directory. For more information click <a href=\"https:\/\/docs.microsoft.com\/en-us\/powerapps\/developer\/data-platform\/walkthrough-register-app-azure-active-directory\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<br \/>\n&#8211; Then create an Application user on the Dynamics 365 CRM. For more information click <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/dynamicscrm-2016\/developers-guide\/mt790170(v%3dcrm.8)#create-an-application-user-associated-with-the-registered-application-in-dynamics-365\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<p style=\"text-align: justify;\">You will get the client id and secret key of your registered application in Azure Active Directory.<\/p>\n<p><strong>Pass the parameter to the HTTP step as below.<\/strong><br \/>\n<strong>Method:<\/strong> \u2013 POST<br \/>\n<strong>URI:<\/strong> \u2013 <a href=\"https:\/\/login.microsoftonline.com\/00000000-0000-0000-0000-000000000000\/oauth2\/token\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/login.microsoftonline.com\/00000000-0000-0000-0000-000000000000\/oauth2\/token<\/a><br \/>\n&lt;This is the OAuth 2.0 Token Endpoint&gt;<br \/>\n<strong>Headers<\/strong><br \/>\nAccept : application\/json<br \/>\nContent-Type : application\/x-www-form-urlencoded<br \/>\n<strong>Body<\/strong><br \/>\ngrant_type=client_credentials<br \/>\nclient_id=&lt;Application Id of registered application in Azure Active Directory&gt;<br \/>\nclient_secret=&lt;Secret key of registered application in Azure Active Directory&gt;<br \/>\nresource= &lt;crm url&gt; e.g. https:\/\/contoso.crm.dynamics.com<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/token-endpoint.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26417 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/token-endpoint.png\" alt=\"token endpoint\" width=\"640\" height=\"528\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/token-endpoint.png 640w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/token-endpoint-300x248.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">After this step, run and test the Power Automate Flow manually to check whether we are getting the access token or not.<\/p>\n<p>\u2022 Add another HTTP Request step where we will execute the Relevance search API request with the following details,<\/p>\n<p><strong>Method:<\/strong> POST<br \/>\n<strong>URI:<\/strong> &lt;organization URL&gt;\/api\/search\/v1.0\/query<br \/>\n<strong>Header:<\/strong> As shown in the below screenshot.<br \/>\n<strong>Body:<\/strong> {\u201csearch\u201d: SearchText} \/\/here \u2018SearchText\u2019 is the variable initialize above which holds the text pass from the Canvas App<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/access-token.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26418 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/access-token.png\" alt=\"access token\" width=\"636\" height=\"544\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/access-token.png 636w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/access-token-300x257.png 300w\" sizes=\"(max-width: 636px) 100vw, 636px\" \/><\/a><\/p>\n<p>\u2022 Save and run the flow again and check the response of the above HTTP Request step.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/url.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26419 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/url.png\" alt=\"url\" width=\"637\" height=\"464\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/url.png 637w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/url-300x219.png 300w\" sizes=\"(max-width: 637px) 100vw, 637px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/search-result-output.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26420 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/search-result-output.png\" alt=\"search result response\" width=\"640\" height=\"541\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/search-result-output.png 640w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/search-result-output-300x254.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><\/p>\n<p>\u2022 Add Parse JSON step after HTTP Request. Here we will pass the response from the above step to the content and will use below sample JSON data to generate the Schema.<\/p>\n<p>{<br \/>\n&#8220;value&#8221;: [<br \/>\n{<br \/>\n&#8220;@search.score&#8221;: 18.536037,<br \/>\n&#8220;@search.highlights&#8221;: {<br \/>\n}<br \/>\n},<br \/>\n{<br \/>\n&#8220;@search.score&#8221;: 10.059773,<br \/>\n&#8220;@search.highlights&#8221;: {<br \/>\n}<br \/>\n},<br \/>\n{<br \/>\n&#8220;@search.score&#8221;: 3.0122523,<br \/>\n&#8220;@search.highlights&#8221;: {<br \/>\n}<br \/>\n}<br \/>\n],<br \/>\n&#8220;facets&#8221;: {},<br \/>\n&#8220;totalrecordcount&#8221;: -1<br \/>\n}<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/body.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26421 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/body.png\" alt=\"body\" width=\"654\" height=\"536\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/body.png 654w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/body-300x246.png 300w\" sizes=\"(max-width: 654px) 100vw, 654px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/generated-schema.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26422 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/generated-schema.png\" alt=\"generated schema\" width=\"631\" height=\"351\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/generated-schema.png 631w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/generated-schema-300x167.png 300w\" sizes=\"(max-width: 631px) 100vw, 631px\" \/><\/a><\/p>\n<p>\u2022 Before we add another step in the Flow, we will first understand the Relevance Search API Response.<\/p>\n<p>Relevance search API response returns a \u2018value\u2019 object, which is an array of individual record along with search score, and fields where the matching word is found (highlights).<\/p>\n<p>Below is the sample response,<br \/>\n{<br \/>\n&#8220;value&#8221;: [<br \/>\n{<br \/>\n&#8220;@search.score&#8221;: 9.740269,<br \/>\n&#8220;@search.highlights&#8221;: {<br \/>\n&#8220;firstname&#8221;: [<br \/>\n&#8220;{crmhit}Rene{\/crmhit}&#8221;<br \/>\n],<br \/>\n&#8220;fullname&#8221;: [<br \/>\n&#8220;{crmhit}Rene{\/crmhit} Sample&#8221;<br \/>\n]\n},<br \/>\n&#8220;@search.entityname&#8221;: &#8220;lead&#8221;,<br \/>\n&#8220;@search.objectid&#8221;: &#8220;79763014-cc8f-4afc-b33b-68a61710350c&#8221;,<br \/>\n&#8220;key&#8221;: &#8220;79763014-cc8f-4afc-b33b-68a61710350clead4&#8221;,<br \/>\n&#8220;ownerid&#8221;: &#8220;f39878a4-163d-eb11-bf68-000d3af05901&#8221;,<br \/>\n&#8220;owneridname&#8221;: &#8220;Sam C2C&#8221;,<br \/>\n&#8220;@search.ownerid.logicalname&#8221;: &#8220;systemuser&#8221;,<br \/>\n&#8220;owningbusinessunit&#8221;: &#8220;019278a4-163d-eb11-bf68-000d3af05901&#8221;,<br \/>\n&#8220;owningbusinessunitname&#8221;: &#8220;&#8221;,<br \/>\n&#8220;@search.owningbusinessunit.logicalname&#8221;: &#8220;businessunit&#8221;,<br \/>\n&#8220;sharedtoprincipalid&#8221;: [],<br \/>\n&#8220;@search.objecttypecode&#8221;: 4,<br \/>\n&#8220;fullname&#8221;: &#8220;Rene Sample&#8221;,<br \/>\n&#8220;versionnumber&#8221;: 2241955,<br \/>\n&#8220;statecode@StringCollection&#8221;: [<br \/>\n&#8220;Open&#8221;<br \/>\n],<br \/>\n&#8220;statecode&#8221;: 0,<br \/>\n&#8220;statuscode@StringCollection&#8221;: [<br \/>\n&#8220;New&#8221;<br \/>\n],<br \/>\n&#8220;statuscode&#8221;: 1,<br \/>\n&#8220;entityimage_url&#8221;: null,<br \/>\n&#8220;lastsyncdate&#8221;: &#8220;\/Date(1608822206278)\/&#8221;,<br \/>\n&#8220;createdon&#8221;: &#8220;12\/24\/2020 3:03 PM&#8221;,<br \/>\n&#8220;modifiedon&#8221;: &#8220;12\/24\/2020 3:03 PM&#8221;,<br \/>\n&#8220;documentbody&#8221;: null,<br \/>\n&#8220;body&#8221;: null,<br \/>\n&#8220;filebody&#8221;: null,<br \/>\n&#8220;emailaddress1&#8221;: null,<br \/>\n&#8220;companyname&#8221;: null,<br \/>\n&#8220;subject&#8221;: &#8220;Interested in Azure Subscription&#8221;,<br \/>\n&#8220;telephone1&#8221;: null<br \/>\n}<br \/>\n],<br \/>\n&#8220;facets&#8221;: {},<br \/>\n&#8220;totalrecordcount&#8221;: -1<br \/>\n}<\/p>\n<p>\u2022 We will now return the required response to the Canvas app. For that, we will first initialize the new Variable called \u201cResult\u201d,<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/initialize-variable-1.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26423 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/initialize-variable-1.png\" alt=\"initialize variable\" width=\"642\" height=\"279\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/initialize-variable-1.png 642w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/initialize-variable-1-300x130.png 300w\" sizes=\"(max-width: 642px) 100vw, 642px\" \/><\/a><\/p>\n<p>\u2022 We will add \u2018Apply to each\u2019 step and will loop through the \u2018value\u2019 from Parse JSON step. This value is actually an array of the individual record.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/value-1.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26424 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/value-1.png\" alt=\"value\" width=\"684\" height=\"163\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/value-1.png 684w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/value-1-300x71.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/value-1-660x157.png 660w\" sizes=\"(max-width: 684px) 100vw, 684px\" \/><\/a><\/p>\n<p>\u2022 We will then add Switch step inside \u2018Apply to each\u2019. Here will check entity logical name of the individual record and based on the entity we will create the response.<\/p>\n<p>We will use the following expression, trim(items(&#8216;Apply_to_each_2&#8217;)?[&#8216;@search.entityname&#8217;])<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/trim.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26425 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/trim.png\" alt=\"\" width=\"650\" height=\"123\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/trim.png 650w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/trim-300x57.png 300w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/a><\/p>\n<p>\u2022 As the Relevance Search API returns multiple entity records, we get different fields per record. For example, if the entity is contact then we get fullname field in the result, similarly, for Opportunity we get Name.<\/p>\n<p style=\"text-align: justify;\">Therefore, to read the values that differ from entity to entity, we would need to add cases for each entity that we want to show the search result in the canvas app.<\/p>\n<p style=\"text-align: justify;\">Here we have added a switch case for Contact, Lead and Opportunity.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-large wp-image-26426\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/switch-case-1024x257.png\" alt=\"switch case\" width=\"665\" height=\"167\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/switch-case-1024x257.png 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/switch-case-300x75.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/switch-case-768x193.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/switch-case-660x166.png 660w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/switch-case.png 1197w\" sizes=\"(max-width: 665px) 100vw, 665px\" \/><\/p>\n<p>\u2022 We will append the formatted response to the \u2018Result\u2019 variable. We will create the response in below format,<\/p>\n<p style=\"text-align: justify;\">Entity1 Logical Name, Entity1 GUID, Entity1 Primary Entity Name Field| Entity2 Logical Name, Entity2 GUID, Entity2 Primary Entity Name Field<\/p>\n<p style=\"text-align: justify;\">Each entity values will be separated by \u2018|\u2019 character and each entity value will contain the entity logical name, its unique identifier and its primary name field.<\/p>\n<p>We will append the string generated by the below expression to the variable,<\/p>\n<p>concat(trim(items(&#8216;Apply_to_each_2&#8217;)?[&#8216;@search.entityname&#8217;]),&#8217;,&#8217;,trim(items(&#8216;Apply_to_each_2&#8217;)?[&#8216;@search.objectid&#8217;]),&#8217;,&#8217;,trim(items(&#8216;Apply_to_each_2&#8217;)?[&#8216;fullname&#8217;]),&#8217;|&#8217;)<\/p>\n<p>Here you would need to change the Primary name field based on the entity. If want, we can add any other additional field of that entity as well.<\/p>\n<p>\u2022 Add final step \u2018Respond to a PowerApp or flow\u2019 as shown below in the screen shot. We will add the Text output and will assign the Result variable.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/result.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-26427 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/result.png\" alt=\"result\" width=\"616\" height=\"195\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/result.png 616w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/result-300x95.png 300w\" sizes=\"(max-width: 616px) 100vw, 616px\" \/><\/a><\/p>\n<p>\u2022 If we run and test this flow we will finally get the response like below which we will read in the canvas app and will show the search results<\/p>\n<p>{<br \/>\n&#8220;text&#8221;: &#8220;lead,79763014-cc8f-4afc-b33b-68a61710350c,Rene Sample|contact,9e79b434-363d-eb11-bf68-002248d4bfa8,Rene Valdes (sample)|&#8221;<br \/>\n}<\/p>\n<p style=\"text-align: justify;\">Here we have got two matching records (contact and lead) for the search text \u2018Rene\u2019.<\/p>\n<h2>Conclusion<\/h2>\n<p style=\"text-align: justify;\">Hence, we learned how to execute the Relevance Search API query in Power Automate. In Part-2 of this blog, we will see how to represent the response data in the Canvas App.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/kanban-board-dynamics-365-crm\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-26428\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/kanban-board.jpg\" alt=\"\" width=\"800\" height=\"200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/kanban-board.jpg 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/kanban-board-300x75.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/kanban-board-768x192.jpg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/01\/kanban-board-660x165.jpg 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Relevance Search has been there for a while in our Dynamics 365 CRM that provides access to exciting new search capabilities in the environment. However, before you use this feature, an administrator must enable relevance search in target environment. Using relevance search we can search across multiple tables\/entities, sorted by relevance. Let us say\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2021\/01\/use-relevance-search-api-in-power-automate-canvas-app-part-1\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1954,16,19,38,1985],"tags":[1867,545,592,1975,2120],"class_list":["post-26408","post","type-post","status-publish","format-standard","hentry","category-canvas-apps","category-dynamics-365","category-dynamics-crm","category-microsoft-powerapps","category-power-automate","tag-canvas-app","tag-dynamics-365-crm","tag-dynamics-crm","tag-power-automate","tag-relevance-search"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/26408","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=26408"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/26408\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=26408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=26408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=26408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}