Using Xrm.Device captureImage to take picture using camera and attach it to notes in Dynamics 365 for Phones and Tablet App


Check the other articles of this series

captureImage method of Xrm.Device allows us to take the picture through the camera and work with that captured image in the code (in this post, we are saving the image in the notes as an attachment).

This method is only available for mobile apps.

Here we have added a custom ribbon button on the Lead entity form.

  • Capture and attach

The capture Image method will allow the user to capture an image using the device camera and attach it to the notes as shown below.

Clicking on “Capture and attach” ribbon button, opens the camera for the user to take the pic as shown below.

Clicking on OK will ask the user to choose the image editor.

Users can edit the image and click on done.

The dialog informs the user that images have been attached.

Users can refresh the timeline to see the attached image in notes.

If we try using the captureImage method inside the Dynamics 365’s web application, we get the below error, because it is only supported for mobile devices.

The method will throw the below error in case of Web Application

“Operation {0} is not supported by platform”

The sample code for captureImage


function CaptureImage(entityId) {

entityId = entityId.replace(/[{}]/g,'');

var imageOptions = {};
imageOptions.allowEdit = true;

Xrm.Device.captureImage(imageOptions).then(
function (data) {

// attach the captured image as attachment to note
var entity = {};
entity.subject = "Sample Subject";
entity.documentbody = data.fileContent;
entity.filename = data.fileName;
entity.mimetype = data.mimeType;
entity.notetext = "Sample Text";

// lead entity sample
entity["objectid_lead@odata.bind"] = "/leads(" + entityId + ")";

Xrm.WebApi.online.createRecord("annotation", entity).then(
function success(result) {
var newEntityId = result.id;

var alertStrings = { confirmButtonLabel: "OK", text: "Image successfully attached to note. Please refersh the timeline" };
var alertOptions = { height: 200, width: 300 };
Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);

},
function (error) {

Xrm.Utility.alertDialog("Error occured while attaching image to notes. Please try again");
}
);

},
function (error) {
Xrm.Utility.alertDialog("Error occured while capturing image. Please try again");
}
);
}

Add Crm Parameter to pass the GUID of the record to the method

CaptureImage

Thus, using captureImage makes it easy for the end-user to capture and attach the image to notes through a click of a button.

To update an entity’s image, we can click on the image itself which will open up the dialog to either use the camera, upload image from the gallery, or revert it to the default image (in not default).

Also check out the wonderful tool Notes Metadata Manager , which provides additional capabilities like adding metadata to the attachments, organise attachments using folder structure, drag and drop attachments, upload multiple attachments etc.

Hope it helps..

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

Power Spark

Power Spark By Shrangarika

Van Carl Nguyen

Exploration of Power Platform

My Trial

It is my experience timeline.

Power⚡Thomas

Sharing my knowledge and experience about the Microsoft Power Platform.

Arpit Power Guide

a guide to powering up community

Welcome to the Blog of Paul Andrew

Sponsored by Cloud Formations Ltd

Deriving Dynamics 365

Deriving Solutions and features on Power Platform/Dynamics 365

The CRM Ninja

Thoughts & musings from a Dynamics 365 Ninja!

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog

Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform

Knowhere365

Specific topics by Django Lohn on the whole Microsoft365 Stack

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions

MG

Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue MVP

A Microsoft Business Applications MVP

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM

CRM TIPS BY PRM

Mail to crmtipsbyprm@gmail.com for queries and suggestions

nijos.dev

Giving back to the community what I have learned

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.

CRM Keeper

Dynamics 365 Customer Engagement, CRM, Microsoft CRM, Dynamics CRM