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:
- Click Take Photo button
- Take photo on tablet camera
- 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)
}