web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

How to call Xrm.Device.captureImage multiple times?

(0) ShareShare
ReportReport
Posted on by

Hi,

I'm trying to use the Xrm.Device.captureImage function but with a better user experience, as currently if users takes many photos, its a slow process having to do these steps for each photo:

  1. Click Take Photo button
  2. Take photo on tablet camera
  3. Confirm the photo taken

So, I would like to call the Xrm.Device.captureImage function until the user click on Cancel when taking photos.

I have done few test, and I'm not able to do in a simple do/while loop, as when the captureImage is called on second time, it throws exception from captureImage function

Error: Operation is being aborted by user. Media content wasn't captured.

As you see, I'm adding the photo taken as annotation to an account

this.takePhoto = function () {
		
        Xrm.Page.data.save();
		 
		let i = 0;
		
		do {
		
		i = i   1;		
		
		 Xrm.Device.captureImage().then(
		 
		 function success(result) {
		 
				var patt = /[^.] $/;
				var match = patt.exec(result.fileName);
				var photoTitle = "Photo - ";
				var note = Object();
				note["mimetype"] = result.mimeType;
				note["objectid_account@odata.bind"] = "/accounts("   Xrm.Page.data.entity._entityId.guid   ")";
				note["documentbody"] = result.fileContent;

				var d = new Date();
				var t = d.getHours()   '.'   d.getMinutes()   '.'   d.getSeconds();
				photoTitle  = t;
				note["subject"] = photoTitle;
				note["filename"] = photoTitle   "."   match[0];
				
				Xrm.WebApi.createRecord("annotation", note);
				
		
		 },
		 function (error) {
		 // Show Error
		 Xrm.Utility.alertDialog("Error :"   error.message, null);
		 }
		 );
		
		
		
		} while (i < 3)
}

I have the same question (0)
  • Jorge_ Profile Picture
    on at
    RE: How to call Xrm.Device.captureImage multiple times?

    Thanks Frank, JS calls should not be synchronous?

    I'll reserch how do add an event to the call, thanks.

    Will provide code if I can make it work

  • Community Member Profile Picture
    on at
    RE: How to call Xrm.Device.captureImage multiple times?

    Hi,

    The time interval of the do while loop will be very short, resulting in Xrm.Device.captureImage() indeed unable to capture any images.

    You can try to add an event to the Take Photo button. Calling this function after it is triggered will not cause such a problem.

    If this helped you, I'd appreciate it if you'd mark this as a Verified Answer, which may in turn help others as well.

    Best Regards,

    Frank Gong

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
DAnny3211 Profile Picture

DAnny3211 253

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 137 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 90 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans