{"id":12274,"date":"2018-07-11T18:21:10","date_gmt":"2018-07-11T12:51:10","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=12274"},"modified":"2020-05-27T10:54:02","modified_gmt":"2020-05-27T10:54:02","slug":"create-attachment-in-crm-with-camera-control-using-canvas-app-in-powerapps","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2018\/07\/create-attachment-in-crm-with-camera-control-using-canvas-app-in-powerapps\/","title":{"rendered":"Create Attachment in CRM with Camera Control using Canvas App in PowerApps"},"content":{"rendered":"<h2>Introduction:<\/h2>\n<p>Designing and building business apps using the Canvas app in Microsoft PowerApps is an intuitive experience with the ability to drag and drop elements onto the canvas. This gives the users the freedom to utilize and integrate business data from Common Data Service along with the choice of 200 data sources. Using the blank canvas, users can design tailored user interface for their business applications.<\/p>\n<p>In the previous blog, we have seen <a href=\"https:\/\/www.inogic.com\/blog\/2018\/07\/create-records-in-dynamics-365-with-canvas-powerapp\/\" target=\"_blank\" rel=\"noopener noreferrer\">how to create a record in CRM using the Canvas app in PowerApps<\/a>.<\/p>\n<p>In this blog, we will explore how you can attach a photo to CRM record using the Camera control in Microsoft PowerApps.<\/p>\n<h3>Using the PowerApps Camera control to attach photos to Dynamics 365 records<\/h3>\n<p>1. First, you need to sign in to the PowerApps <a href=\"https:\/\/powerapps.microsoft.com\/en-us\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/powerapps.microsoft.com\/en-us\/<\/a> with your Microsoft work email id. It will open the<strong> <em>PowerApps Web Studio.<\/em><\/strong><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-12275\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/07\/Create-Attachment-in-CRM-with-Camera-Control-using-Canvas-App-in-PowerApps1.png\" alt=\"Create Attachment in CRM with Camera Control using Canvas App in PowerApps\" width=\"816\" height=\"257\" \/><\/p>\n<p>2. Now, you need to click on \u2018<strong><em>Create an app\u2019<\/em><\/strong> and then select the \u2018<strong><em>Phone Layout\u2019<\/em><\/strong> under <strong><em>\u2018Start with a blank canvas or a template\u2019.<\/em><\/strong> This should open a blank canvas.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-12276\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/07\/Create-Attachment-in-CRM-with-Camera-Control-using-Canvas-App-in-PowerApps2.png\" alt=\"Create Attachment in CRM with Camera Control using Canvas App in PowerApps\" width=\"823\" height=\"619\" \/><\/p>\n<p>3. Then, insert a <strong><em>\u2018Gallery\u2019<\/em><\/strong> control on the canvas.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-12277\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/07\/Create-Attachment-in-CRM-with-Camera-Control-using-Canvas-App-in-PowerApps3.png\" alt=\"Create Attachment in CRM with Camera Control using Canvas App in PowerApps\" width=\"814\" height=\"419\" \/><\/p>\n<p>4. Now, go to <strong><em>View &gt; Data sources &gt; Add data source<\/em><\/strong>. Here, add Dynamics 365 as a data source and add corresponding entities (in this example, we are adding <strong>Account<\/strong> and <strong>Notes<\/strong> entities).<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-12278\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/07\/Create-Attachment-in-CRM-with-Camera-Control-using-Canvas-App-in-PowerApps4.png\" alt=\"Create Attachment in CRM with Camera Control using Canvas App in PowerApps\" width=\"820\" height=\"307\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-12279\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/07\/Create-Attachment-in-CRM-with-Camera-Control-using-Canvas-App-in-PowerApps5.png\" alt=\"Create Attachment in CRM with Camera Control using Canvas App in PowerApps\" width=\"818\" height=\"448\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"padding-left: 150px;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-12280\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/07\/Create-Attachment-in-CRM-with-Camera-Control-using-Canvas-App-in-PowerApps6.png\" alt=\"Create Attachment in CRM with Camera Control using Canvas App in PowerApps\" width=\"291\" height=\"412\" \/><\/p>\n<p>5. Next, set the Gallery<strong><em> Item <\/em><\/strong>property to <strong><em>Accounts<\/em>.<\/strong><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-12281\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/07\/Create-Attachment-in-CRM-with-Camera-Control-using-Canvas-App-in-PowerApps7.png\" alt=\"Create Attachment in CRM with Camera Control using Canvas App in PowerApps\" width=\"821\" height=\"405\" \/><\/p>\n<p>6. Now, set the <strong><em>OnSelect<\/em><\/strong> property of <strong><em>Next Arrow<\/em><\/strong> to; Navigate(ScreenAccountDetail,ScreenTransition.Cover,{accountRecord : Gallery3.Selected})<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-12282\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/07\/Create-Attachment-in-CRM-with-Camera-Control-using-Canvas-App-in-PowerApps8.png\" alt=\"Create Attachment in CRM with Camera Control using Canvas App in PowerApps\" width=\"825\" height=\"232\" \/><\/p>\n<p>Now, <strong><em>OnSelect <\/em><\/strong>or click of the <strong><em>Next Arrow<\/em><\/strong>, it will navigate to <strong><em>\u201cScreenAccountDetail\u201d<\/em><\/strong> screen.<\/p>\n<p>Here we are sending the selected row as <em>\u201c<strong>accountRecord<\/strong>\u201d<\/em> into the next screen which means the whole data row will be available on screen <em>\u201c<strong>ScreenAccountDetal<\/strong>\u201d.<\/em><\/p>\n<p>7. Next, add another screen for capturing the image from the <strong><em>Camera Control<\/em><\/strong>. Add Camera control on the screen and set the position and size to see the image while capturing.<\/p>\n<p style=\"padding-left: 120px;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-12283\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/07\/Create-Attachment-in-CRM-with-Camera-Control-using-Canvas-App-in-PowerApps9.png\" alt=\"Create Attachment in CRM with Camera Control using Canvas App in PowerApps\" width=\"290\" height=\"513\" \/><\/p>\n<blockquote><p><strong><em>Note:<\/em><\/strong><em> Here we have added a <strong>Label <\/strong>and set its <strong>Text <\/strong>property to<strong> \u201cClick anywhere on camera to capture image\u201d<\/strong> below the camera control to let the user know how to capture the image from control.<\/em><\/p><\/blockquote>\n<p>Set <strong><em>OnSelect<\/em><\/strong> property of Camera Control to;<\/p>\n<p>ClearCollect(CameraImages,Camera1_1.Photo);<\/p>\n<p>Clear(Image);<\/p>\n<p>ForAll(CameraImages,Collect(Image,{Filename:&#8221;img.jpg&#8221;,fileBody:Url}));Back()<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-12284\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/07\/Create-Attachment-in-CRM-with-Camera-Control-using-Canvas-App-in-PowerApps10.png\" alt=\"Create Attachment in CRM with Camera Control using Canvas App in PowerApps\" width=\"821\" height=\"63\" \/><\/p>\n<p><strong>CameraImages:<\/strong> In this collection, captured images will be stored as URL which will be in the base64 string format with prefix \u201cdata:image\/jpeg;base64,\u201d or \u201cdata:image\/png;base64,\u201d.<\/p>\n<p><strong>Image:<\/strong> this is the collection in which we store the image name and image captured by the camera control.<\/p>\n<blockquote><p><strong><em>Note:<\/em><\/strong><em> Here we are storing one image at a time to CRM.<\/em><\/p><\/blockquote>\n<p>8. Insert <strong><em>Blank Screen<\/em><\/strong> and add the control to save the captured image as <strong><em>Attachments<\/em><\/strong> in Dynamics CRM.<\/p>\n<p style=\"padding-left: 90px;\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-12285\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/07\/Create-Attachment-in-CRM-with-Camera-Control-using-Canvas-App-in-PowerApps11.png\" alt=\"Create Attachment in CRM with Camera Control using Canvas App in PowerApps\" width=\"539\" height=\"482\" \/><\/p>\n<blockquote><p><strong>Note:<\/strong> We have added a scrollable screen and all the controls added in the section. You can use the blank screen as well.<\/p><\/blockquote>\n<p>Set the <strong><em>Text<\/em><\/strong> property of the <strong><em>Label<\/em><\/strong> to; accountRecord.name<\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-12286\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2018\/07\/Create-Attachment-in-CRM-with-Camera-Control-using-Canvas-App-in-PowerApps12.png\" alt=\"Create Attachment in CRM with Camera Control using Canvas App in PowerApps\" width=\"822\" height=\"627\" \/><\/p>\n<p>Set <strong>OnSelect<\/strong> property of Camera Icon to; Navigate(CameraAccount,ScreenTransition.Fade)<\/p>\n<p>On click of the Camera Icon, it will navigate to Camera Screen (<strong>added in step 7<\/strong>) where you can capture the image.<\/p>\n<p>Set <strong>OnSelect<\/strong> property of Reset Icon to; Clear(Image)<\/p>\n<p>On click of the Reset Icon, it will clear the <strong>Image<\/strong> collection.<\/p>\n<p>Set <strong>OnSelect<\/strong> property of <strong>Clear<\/strong> button to; Reset(title);Reset(description);Clear(Image)<\/p>\n<p>This button will clear the Title, Description and Image collection.<\/p>\n<p>Set <strong>OnSelect<\/strong> property of <strong>Save Image<\/strong> button to;<\/p>\n<h3>Updated Patch request:<\/h3>\n<p><strong>Patch(Notes,Defaults(Notes),{subject:title.Text ,notetext :description.Text,_objectid_value : accountRecord.accountid, _objectid_type : &#8220;accounts&#8221;,filename: &#8220;img.jpg&#8221;,documentbody :<\/strong><\/p>\n<p><strong>If(StartsWith(First(Image).fileBody,&#8221;data:image&#8221;),Replace(First(Image).fileBody,1, Len(Left(First(Image).fileBody,Find(&#8220;,&#8221;,First(Image).fileBody))),&#8221;&#8221;),First(Image).fileBody)});<\/strong><\/p>\n<p>Here we are creating the records in the <strong><em>Annotation<\/em><\/strong> entity regarding the account. So, to set the regarding field we have to pass the <strong><em>objectidvalue<\/em><\/strong> and <strong><em>objectidtype<\/em><\/strong>.<\/p>\n<p>In our case, we are creating the Annotation record against the Account entity, so we pass the objectidvalue as selected account id and objectidtype as accounts. Also, we are setting the default file name as \u201cimg.jpg\u201d, you can use a different name with <strong>.jpg<\/strong> extension.<\/p>\n<blockquote>\n<p style=\"text-align: justify;\"><strong><em>Note: <\/em><\/strong><em>To create attachments in CRM we have to pass the document body in base64 string. In the canvas app, the camera control gives the URL as base64 string of captured image with the prefix \u201c<strong>data:image\/jpeg;base64<\/strong>,\u201d or \u201c<strong>data:image\/png;base64<\/strong>,\u201d. So while creating the annotation record in CRM we have to remove \u201c<strong>data:image\/jpeg;base64<\/strong>,\u201d\u00a0or \u201c<strong>data:image\/png;base64<\/strong>,\u201d from the URL and if you want to display the attachment image of CRM in <strong>Image control of canvas app<\/strong> then you have to append \u201c<strong>data:image\/jpeg;base64<\/strong>,\u201d\u00a0or \u201c<strong>data:image\/png;base64<\/strong>,\u201d in the prefix of document body.<\/em><\/p>\n<\/blockquote>\n<h2><strong>Conclusion:<\/strong><\/h2>\n<p>By following the above steps, we can create the Annotation record in CRM with the help of the Camera Control from the Canvas app in Microsoft PowerApps.<\/p>\n<p><a href=\"https:\/\/www.maplytics.com\/miscellaneous\/effective-sales-territory-management-using-map-visualization-dynamics-crm\/\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-6803\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/07\/Effectively-Manage-Sales-Territories-on-a-map-within-Microsoft-Dynamics-CRM.png\" alt=\"Effectively Manage Sales Territories on a map within Microsoft Dynamics CRM\" width=\"820\" height=\"205\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: Designing and building business apps using the Canvas app in Microsoft PowerApps is an intuitive experience with the ability to drag and drop elements onto the canvas. This gives the users the freedom to utilize and integrate business data from Common Data Service along with the choice of 200 data sources. Using the blank\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2018\/07\/create-attachment-in-crm-with-camera-control-using-canvas-app-in-powerapps\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":23719,"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":[16,18,19,44],"tags":[241,246,572,672],"class_list":["post-12274","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-365","category-dynamics-365-v9-2","category-dynamics-crm","category-power-apps","tag-camera-control-using-canvas-app-in-powerapps","tag-canvas-app-in-powerapps","tag-dynamics-365-powerapps","tag-dynamics-crm-powerapps"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/12274","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=12274"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/12274\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/23719"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=12274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=12274"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=12274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}