{"id":4042,"date":"2020-12-16T11:19:27","date_gmt":"2020-12-16T11:19:27","guid":{"rendered":"https:\/\/himbap.com\/blog\/?p=4042"},"modified":"2020-12-16T11:20:05","modified_gmt":"2020-12-16T11:20:05","slug":"update-entity-from-canvas-app-using-patch","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=4042","title":{"rendered":"Update entity from Canvas App using Patch"},"content":{"rendered":"<p><strong>Introduction<\/strong><br \/>\nIn <a href=\"https:\/\/himbap.com\/blog\/?p=4016\">earlier article<\/a> we discussed about how updating entity from canvas app using Power Automate. This process is works fine if you don&#8217;t want to update current entity because executing Flow will take some time and you won&#8217;t be able to see the changes quickly so in this post we are going to discuss other option to update entity from canvas app and you will be able to see changes quickly.<br \/>\n<strong>Details<\/strong><br \/>\nIn our example we have event entity where we have a lookup field called Event Organizer. We want to setup this lookup field from the canvas app gallery control. You can refer our earlier posts to create this canvas app. On Select of the gallery control we are using Patch command like below<\/p>\n<p><a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2020\/12\/PatchToUpdateLookupfield.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4043 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2020\/12\/PatchToUpdateLookupfield-300x114.png\" alt=\"PatchToUpdateLookupfield\" width=\"300\" height=\"114\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2020\/12\/PatchToUpdateLookupfield-300x114.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2020\/12\/PatchToUpdateLookupfield-1024x391.png 1024w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2020\/12\/PatchToUpdateLookupfield-624x238.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2020\/12\/PatchToUpdateLookupfield.png 1610w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>You can refer about Patch command from <a href=\"https:\/\/docs.microsoft.com\/en-us\/powerapps\/maker\/canvas-apps\/functions\/function-patch\">here<\/a>.<\/p>\n<p>In our example we are using this Patch command.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nPatch(\r\n    'Events',\r\n    First(\r\n        Filter(\r\n            Events,\r\n            Event = [@ModelDrivenFormIntegration].Item.Event\r\n        )\r\n    ),\r\n    {\r\n        'Event Organizer': LookUp(\r\n            Accounts,\r\n            Account = ThisItem.Account\r\n        )\r\n    }\r\n);\r\nModelDrivenFormIntegration.RefreshForm(&quot;true&quot;);\r\n\r\n<\/pre>\n<p>Based on the Syntax of Patch command Patch( DataSource, BaseRecord, ChangeRecord1 [, ChangeRecord2, \u2026 ]) we are passing following parameters.<br \/>\nEvents &#8211; This is name of our data source<br \/>\nFirst(Filter())- We are using this identify Event record which we need to Update<br \/>\n{&#8216;Event Organizer&#8217;:&#8230;} &#8211; This is the place where are setting up Account lookup<\/p>\n<p>Using above option we can update lookup and other fields if required and user will be able to see changes quickly.<br \/>\n<a href=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2020\/12\/update-lookupfield.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-4044 aligncenter\" src=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2020\/12\/update-lookupfield-300x280.png\" alt=\"update lookupfield\" width=\"300\" height=\"280\" srcset=\"https:\/\/himbap.com\/blog\/wp-content\/uploads\/2020\/12\/update-lookupfield-300x280.png 300w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2020\/12\/update-lookupfield-624x582.png 624w, https:\/\/himbap.com\/blog\/wp-content\/uploads\/2020\/12\/update-lookupfield.png 682w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Summary<br \/>\nThis is how we can use Patch command in canvas app to set lookup field.<\/p>\n<p>Hope it will help someone!<br \/>\n<strong>Keep learning, Keep sharing !!<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In earlier article we discussed about how updating entity from canvas app using Power Automate. This process is works fine if you don&#8217;t want to update current entity because executing Flow will take some time and you won&#8217;t be able to see the changes quickly so in this post we are going to discuss other option to update entity&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=4042\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":4043,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[817,402,728],"tags":[841,842,840],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4042"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4042"}],"version-history":[{"count":3,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4042\/revisions"}],"predecessor-version":[{"id":4047,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4042\/revisions\/4047"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/media\/4043"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}