Xrm.Device: Capture Image on Mobile

Applies to Dynamics 365 (online), version 9.x

Microsoft introduces a new namespace “Xrm.Device” in Dynamics 365 API version v9.0. This namespace offers the method Xrm.Device.captureImage that we will use here to take the photo and attach to our entity. This makes Dynamics CRM engineer's life simple. 'CaptureImage' is one of the helpful APIs for Dynamics 365.

In this blog, we will see how this API helps Dynamics 365 mobile users to capture an image and use it in Dynamics CRM. Note this API invokes the device camera to capture an image and is supported for the mobile clients only.

API Syntax

Xrm.Device.captureImage(imageOptions).then(successCallback, errorCallback)

Parameters

Xrm.Device parameters

Return Value

On success, it returns a base64 encoded image object with the attributes specified earlier.

Example

For captureImage, first, we need to place a desired button on our entity. As we are creating a test example, so call this button as “Test”.

Our capture code will be against this button, i.e. on-click of “Test” button.

simple entity capture image

Code

Following is the code to capture the image on mobile device.

capture the image on mobile device

Testing

To test capture image from mobile, first, you need to add your desired entity to any unified interface hub. This unified interface hub is accessible from mobile device.

testing sales hub

Mobile layout:

mobily layout dynamics crm

xrm device mobile layout

When button is clicked, the mobile camera opens automatically to capture image.

camera testing result

simple entity choose image

Conclusion

Xrm.Device.captureImage makes dynamics CRM developer’s life easy. ‘CaptureImage’ is one of the useful APIs for Dynamics 365 mobile users. CaptureImage is handy option for field users.

Reference

Xrm.Device (Client API reference)

captureImage (Client API reference)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.