想要把BIPubliser 生成的报表作为邮件附件发送,首先要知道报表路径,我们知道报表路径是存在 ps_cdm_list 和 ps_cdm_file_list 两张表里的,当报表发布之后,我们可以用SQL语句
将报表在服务器的路径查出来。
- SQlExec("select contentid from ps_cdm_file_list where prcsinstance=:1 and cdm_file_type=:2",&Process_instance,&Report_file_type,&Contenid);
- /参数1是Process_instance ,参数2 是报表文件类型;返回报表内容ID;
- /然后跟剧&Contenid 查出报表在服务器的路径;
- SQLExec("SELECT outputdir FROM PS_CDM_LIST where prcsinstance = :1 and contentid=:2 ", &Process_Instance, &Contenid, &OutPutDir);
就得不到报表路径。为了解决这个问题,我们可以把当前线程睡眠一段时间,
- Local string &ReportName = "Z_RPT_PRB";
- &OUTTYPE = "PDF";
- rem SQLExec("SELECT contentid FROM ps_cdm_file_list where prcsinstance = :1", &Process, &en);
- &contenid = 0;
- While (&contenid = 0)
- SQLExec("SELECT contentid FROM ps_cdm_file_list where prcsinstance = :1 and cdm_file_type=:2 ", &Process, &OUTTYPE, &contenid);
- &s = 40;
- GetJavaClass("java.lang.Thread").sleep(1000 * &s);
- End-While;
- SQLExec("SELECT outputdir FROM PS_CDM_LIST where prcsinstance = :1 and contentid=:2 ", &ProcessInstance, &contenid, &OutPutDir);
- import PT_MCF_MAIL:*;
-
- &ProcessInstance = Z_TEST_AET.PROCESS_INSTANCE;
-
- Local string &Process = String(&ProcessInstance);
-
- Local string &ReportName = "Z_RPT_PRB";
- &OUTTYPE = "PDF";
- rem SQLExec("SELECT contentid FROM ps_cdm_file_list where prcsinstance = :1", &Process, &en);
- &contenid = 0;
- While (&contenid = 0)
- SQLExec("SELECT contentid FROM ps_cdm_file_list where prcsinstance = :1 and cdm_file_type=:2 ", &Process, &OUTTYPE, &contenid);
- &s = 40;
- GetJavaClass("java.lang.Thread").sleep(1000 * &s);
- End-While;
- SQLExec("SELECT outputdir FROM PS_CDM_LIST where prcsinstance = :1 and contentid=:2 ", &ProcessInstance, &contenid, &OutPutDir);
-
- Local string &AttachmentUrl = "/ps/psreports/" | &OutPutDir | "/" | &ReportName | "." | "pdf";
-
- Local PT_MCF_MAIL:MCFOutboundEmail &email = create PT_MCF_MAIL:MCFOutboundEmail();
- &FromAddress = <A href="mailto:AAAA@sina.cn">AAAA@sina.cn</A>;
- &ToList = "XXXXXXXx@163.com";
- &Subject = "Test Report as Attachment";
- &email.From = &FromAddress;
- &email.Recipients = &ToList;
- &email.Subject = &Subject;
- &email.Text = "Test";
- Local string &plain_text = "Test Add Attachment!";
- Local PT_MCF_MAIL:MCFBodyPart &text = create PT_MCF_MAIL:MCFBodyPart();
- &text.Text = &plain_text;
-
- rem Local PT_MCF_MAIL:MCFBodyPart &attach1 = create PT_MCF_MAIL:MCFBodyPart();
- rem &attach1.SetAttachmentContent("Ocean Wave.jpg", %FilePath_Relative, "Ocean Wave.jpg", "Ocean Wave", "", "");
- /* %FilePath_Relative indicates the file is available at Appserver's FILES?
- dierctory */
-
- Local PT_MCF_MAIL:MCFBodyPart &attach2 = create PT_MCF_MAIL:MCFBodyPart();
- &attach2.SetAttachmentContent(&AttachmentUrl, %FilePath_Absolute, "Attachment.pdf", "Attachmen", "", "");
- /* The Sample.jpg is available in the "public" folder of my-server machine*/
-
-
- Local PT_MCF_MAIL:MCFMultipart &mp = create PT_MCF_MAIL:MCFMultipart();
- &mp.AddBodyPart(&text);
- rem &mp.AddBodyPart(&attach1);
- &mp.AddBodyPart(&attach2);
-
- &email.MultiPart = ∓
-
- Local integer &res = &email.Send();
-
- Local boolean &done;
-
- Evaluate &resp
- When %ObEmail_Delivered
- /* every thing ok */
- &done = True;
- Break;
-
- When %ObEmail_NotDelivered
- /*-- Check &email.InvalidAddresses, &email.ValidSentAddresses
- and &email.ValidUnsentAddresses */
- &done = False;
- Break;
-
- When %ObEmail_PartiallyDelivered
- /* Check &email.InvalidAddresses, &email.ValidSentAddresses
- and &email.ValidUnsentAddresses; */
- &done = True;
- Break;
-
- When %ObEmail_FailedBeforeSending
- /* Get the Message Set Number, message number;
- Or just get the formatted messages from &email.ErrorDescription,
- &email.ErrorDetails;*/
-
- &done = False;
- Break;
- End-Evaluate;