How to send Email with Attached Dynamics 365 CRM Report in Resco Mobile App

User Review
0 (0 votes)


Recently we had a business requirement, where we needed to send Dynamics 365 CRM Report through Email from Resco Mobile App. In this blog, you will see how to do the same. To achieve this,  follow the steps given below:

1) We added a custom button (i.e.Command) on the Entity Form of the Invoice entity. Please refer below screenshots:

2) Then, we added a ‘HTML’ file (with ‘JavaScript’ code) in the ‘Iframe’ of Entity Form of Invoice entity in order to bind ‘Click Event’ with the ‘Send Invoice’ button. Please refer below screenshot:

3) Next, we added two function (i.e. downloadReport and sendEmailWithAttachment) in our script, as shown below:

//Funtion for downloading reports

downloadReport = function (fileName, format, reportId, regarding, success, failed, scope) {

/// <summary>Downloads the MS Dynamics report into a file.</summary>

/// <param name=”fileName” type=”String”>A file name for resulting file. Leave &quot;null&quot; to let app to safely generate the file name and extension.</param>

/// <param name=”format” type=”String”>One of following formats (must be supported in Dynamics): XML, CSV, PDF, MHTML, EXCELOPENXML, WORDOPENXML, IMAGE.</param>

/// <param name=”success” type=”function(location)”>A callback function that is called with the full path to downloaded file.</param>

/// <param name=”failed” type=”function(errorMsg)”>A callback which is called in case of error.</param>

/// <param name=”scope” type=”Object”>The scope for callbacks.</param>

try {

var params = JSON.stringify({

format: format || “PDF”,

outputFileName: fileName,

outputFolder: this.outputFolder,

outputFilePath: this.outputFilePath, // for internal use only

reportId: reportId,

regardingEntity: regarding ? regarding.entityName : null,

regardingId: regarding ? : null


//command for downloading report

MobileCRM.bridge.command(“downloadReport”, params, success, failed, scope);

} catch (e) {

MobileCRM.bridge.alert(“An Error Has occurred ” + e);



//Funtion for sending email

sendEmailWithAttachment = function (filePath, refInvoice) {

try {

/// <summary>Sends an email</summary>

/// <param name=”filePath” type=”String”> A path of the resulting file</param>

/// <param name=”entity” type=”MobileCRM.Reference”>The related entity reference.</param>

var attachments = [];  /// Array of attachments to send. Element must be a full path or a reference to a note.



“”, /// email address

“Invoice”,  /// email subject

“\nHi,\n\n Please Find Attached Invoice. \n\n Regards.\n Kabir”,       /// email body


refInvoice, null,

function (error) {

_resultingReport = null;


}, null);

} catch (e) {

MobileCRM.bridge.alert(“An Error Has occurred ” + e);


4) And then used these functions in the ‘MobileCRM.UI.EntityForm.onCommand’ event, as shown below:


function (EntityForm) {

_entInvoice = EntityForm;

try {

_refInvoice = new MobileCRM.Reference(EntityForm.entity.entityName,, EntityForm.entity.primaryName);

downloadReport(“”, “pdf”, “32C85C59-7D04-E711-80E6-00155DB8652A”, _refInvoice,

function (result) {

MobileCRM.bridge.alert(“Report Downloaded Successfully!”);

_resultingReport = result;

if (_resultingReport != null) {

//This function sents email with attached report

sendEmailWithAttachment(_resultingReport, _refInvoice);



function (error) {

_resultingReport = null;




} catch (e) {

MobileCRM.bridge.alert(“An Error Has occurred ” + e);



5) Next, we published the Resco Mobile Project and synced the Resco Mobile App with the same. And then navigated to the Invoice record and clicked on the ‘Send Invoice’ button (i.e. Custom Command). Please refer below screenshot:

6) After the button is clicked, the email window is displayed with ‘Invoice Report’ added to the email as an attachment. Please refer below screenshot:

7) Next, ‘Send’ button was clicked and the Email with Attachment was sent to the recipient. Please refer below screenshot:


  • In order to send the Email from Resco Mobile App, we need to configure ‘Online Exchange’ (i.e. Outlook) in the Resco Mobile Project
  • While using ‘Offline Mode’, we need to sync the Resco Mobile App after clicking the ‘Send’ button in order to send an email to the recipient
  • We need to make sure that the Dynamics 365 CRM Reports are enabled for Resco Mobile App in the organization

In this way, technicians can use the ‘Send Email’ functionality in order to send emails with an attached report (such as invoice) through Resco Mobile App while working on a job at the client-side.