2013-01-18 29 views
2
打開打印對話框報告

我試圖強制打開打印對話框,以便所有用戶所要做的就是設置電子郵件地址並按下確定。我找到了關於如何在沒有打印對話框的情況下將報告打印到文件或打印機的多個教程,但這不是我要找的。從代碼

通常通過電子郵件發送報告,用戶顯示報告,單擊工具欄中的打印圖標,然後選擇電子郵件併發送。我想自動刪除前兩個步驟。

這是我迄今爲止做這個嘗試中的一個,但無濟於事。

void emailInvoice() 
{ 
Args    args; 
ReportRun   rr; 
Report    rb; 
PrintJobSettings pjs; 
CustInvoiceJour  record; 
; 

select record where record.RecId == 5637175089; 

args = new Args("SalesInvoice"); 
args.record(record); 
args.parmEnum(PrintCopyOriginal::OriginalPrint); 

// Set report run properties 
rr = new ReportRun(args,''); 
rr.suppressReportIsEmptyMessage(true); 
rr.query().interactive(false); 

// set report properties 
rb = rr.report(); 
rb.interactive(true); 

// set print job settings 
pjs = rr.printJobSettings(); 
pjs.fileName(strfmt("C:\\Users\\gbonzo\\Desktop\\%1.pdf", record.SalesId)); 
pjs.fitToPage(true); 
// break the report info pages using the height of the current printer's paper 
pjs.virtualPageHeight(-1); 


// force PDF printing 
pjs.format(PrintFormat::PDF); 
pjs.setTarget(PrintMedium::Mail); 
pjs.viewerType(ReportOutputUserType::PDF); 

// lock the print job settings so can't be changed 
// X++ code int the report may try to change the destination 
// to the screen for example but this does not make 
// sense when running a report here 
pjs.lockDestinationProperties(true); 

// Initialize the report 
rr.init(); 

rr.run(); 
} 

在此先感謝您的幫助!

+0

我有我的疑惑: 1)CustInvoiceJour記錄; 和 2)args = new Args(「SalesInvoice」); – SamekaTV

回答

0

您必須在調用run()方法之前調用ReportRun類的prompt()方法。

if (rr.prompt()) 
{ 
    rr.run(); 
} 

prompt()方法將顯示打印對話框。如果你想讓你的用戶更容易使用SysMailer類,那麼看看quickSend()方法。

+0

我剛試過,當我按下OK時,它只是顯示報告。我選擇了「郵件」並放入收件人,但它不起作用 –

+0

其他時候,它會拋出一個錯誤「ClrObject靜態方法調用錯誤。」 –

+0

@GregBonzo調查這個以避免錯誤http://community.dynamics.com/product/ax/f/33/t/87818.aspx – SamekaTV

1

您是否嘗試過開發一個RunBase標準對話框類(RunBaseBatchPrintable,如果您需要選擇打印機),它將獲取所需的所有對話框字段,然後以編程方式運行報表以傳遞所有需要的參數?我很確定它會起作用,並且可能會留下一個更乾淨的代碼,將用戶交互所需的邏輯報告分開。

這裏讀一個例子:

http://waikeatng.blogspot.com.es/2010/10/using-runbasebatchprintable-class.html

+0

我需要打印機對話框,以便我可以從那裏發送電子郵件,而不是實際上打印 –