In this webinar, our experts showcase a variety of demo use cases of how different components of the...
In today’s blogpost, we will show you how to upload a camera photo from a Canvas App to Dynamics 365 as an attachment on a particular entity record.
Depending on the type of business, it can be common for field employees to take a photo quickly on their phone and store it as an Attachment for a specific record in Dynamics 365. For example: we might have a Canvas App to allow an end user take a photo on the Phone; then automatically attach that as an Attachment for a Case Entity.
Using PowerApps, we created a simple app to display list of Case entity the user owns on a “Case List” Screen; then create another “Photo” Screen that will capture a Photo of the case. Case Entity is only available for Dynamics 365 Customer Service, but this method should be applicable for other entities in Dynamics 365 or Data Flex Pro (Common Data Service).
Add Camera icon in the CaseGallery to navigate to Photo Capture Screen.
OnSelect of CameraIcon, write functions as below
To create an attachment for a record in Dynamics 365/Data Flex Pro, we need to create a Note (annotation) record with Regarding set as selected Case from the Case Gallery. Make sure we add Notes entity to the Canvas app.
“Photo” Screen to capture Photo includes a few main components as shown below:
OnSelect of SaveButton, write a Patch function as below:
Patch(Notes,Defaults(Notes),{Title:TitleTextInput.Text,Description:DescriptionTextInput.Text,'File Name':"photo.png",Document:Substitute(Substitute(Camera1.Photo,"data:image/png;base64,",""),"data:image/jpeg;base64,",""),'Is Document':'Is Document (Notes)'.Yes,Regarding:CaseGallery.Selected})
Note: To create attachments in Dynamics 365 or Data Flex Pro, we need to pass the document body in base64 string. In the canvas app, the camera control gives the image content as base64 with the prefix “data:image/png;base64,” or “data:image/jpeg;base64,”. When creating a Note (annotation) record in Dynamics or Data Flex Pro, we have to remove “data:image/png;base64,” or “data:image/jpeg;base64,”. from the image content
You can test this On Browser or On PowerApps App in your Phone. Select a case by tap on Camera icon of a case on Gallery. Then fill in some information on Title and Description of the Note and take a Photo by tapping on the Camera. Finally, hit Save.
The photo should be created as a new Note of the Case and show in the Timeline. We can download the file and open for viewing.
There are several ways to send photo from Canvas App to Dynamics 365/Data Flex Pro as attachment. This is one of the direct ways that can handle inside PowerApps with native Common Data Service connector.
Don't forget to subscribe to our blog for more helpful tips!
As always, happy PowerApps’ing!!