Skip to main content

Notifications

Announcements

No record found.

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)
}

  • 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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,278 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,011 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans