captureImage invokes the device camera to capture an image
Syntax:
Xrm.Device.captureImage(imageOptions).then(successCallback, errorCallback)
Parameters:
Parameter Name |
Type |
Required |
Description |
imageOptions |
Object |
No |
An object with the following attributes: – allowEdit: Indicates whether to edit the image before saving. Boolean. – height: Height of the image to capture. Number. – preferFrontCamera: Indicates whether to capture image using the front camera of the device. Boolean. – quality: Quality of the image file in percentage. Number. – width: Width of the image to capture. Number.. |
successCallback |
Function |
Yes |
A function to call when image is returned. A base64 encoded image object with the following attributes is passed to the function: – fileContent: Contents of the image file. String – fileName: Name of the image file. String. – fileSize: Size of the image file in KB. Number. – mimeType: Image file MIME type. String. |
errorCallback |
Function |
Yes |
A function to call when the operation fails. |
Return Value:
On success, returns a base64 encoded image object with the attributes specified earlier.
Note: This method is supported only for the mobile clients. (Dynamics 365 for Phones App in Tablet and Mobiles)
Example:
Capture Photo button is created on Account form and OnClick of the button below function CaptureImage configured.
function CaptureImage() {
Xrm.Device.captureImage().then(
function success(result) {
// Update Image
updateImage(Xrm.Page.data.entity.getId(), result.fileContent);
},
function (error) {
// Show Error
Xrm.Utility.alertDialog("Error :" + error.message, null);
}
);
}
// This function will update the Image to Account record
function UpdateImage(accountGuid, ImageContent) {
// define the data to update a record
var data =
{
"entityimage": ImageContent
}
// Update the record
Xrm.WebApi.updateRecord("account", accountGuid, data).then(
function success(result) {
Xrm.Utility.alertDialog("Account Image updated", function () {
// Reload Account form to show the updated Image
Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId());
});
},
function (error) {
Xrm.Utility.alertDialog("Error while updating Account Image : " + error.message, null);
// handle error conditions
}
);
}
Output:
1.Open Dynamics 365 for Phones App in Mobile or Tablet.
2.Navigate to Accounts and open any Account record.
3.Tap on Capture Photo button. System or Mobile Inbuilt Camera will be opened and click on Camera icon to capture the photo.

4. Once photo is captured and saved, you will see the below message. Tap on OK to open the Account record to see the updated image.

Hope you learned this new feature :):):)
Like this:
Like Loading...