Get the output files in zip format after running AE or SQR
--------------------------------------------------------------------------------
Global integer Π
&PI = PSQUERY_AET.PROCESS_INSTANCE;
&query = PSQUERY_AET.QRYNAME;
SQLExec("SELECT B.URL,A.PRCSOUTPUTDIR from
PS_CDM_DIST_NODE B, PS_CDM_LIST A WHERE A.DISTNODENAME = B.DISTNODENAME
AND A.PRCSINSTANCE = :1", &PI,
&url, &output);
REM The file I want
to compress;
&fileNameToZip = &output | "/" |
&query | "-" | &PI | ".xls";
&fileout = &output | "/" | &query |
"-" | &PI | ".zip";
&filename = &query | "-" | &PI |
".xls";
REM The internal zip
file's structure -- internal location of file;
&zipInternalPath = &filename;
Local JavaObject &zip =
CreateJavaObject("java.util.zip.ZipOutputStream",
CreateJavaObject("java.io.FileOutputStream", &fileout, True));
Local JavaObject &file =
CreateJavaObject("java.io.File", &fileNameToZip);
REM to read
&fileNameToZip into a buffer and write it out to &zip;
Local JavaObject &buf =
CreateJavaArray("byte[]", 1024);
Local number &byteCount;
Local JavaObject &in =
CreateJavaObject("java.io.FileInputStream", &fileNameToZip);
Local JavaObject &zipEntry =
CreateJavaObject("java.util.zip.ZipEntry", &zipInternalPath |
"/" | &file.getName());
&zipEntry.setTime(&file.lastModified());
&zip.putNextEntry(&zipEntry);
&byteCount = &in.read(&buf);
While &byteCount > 0
&zip.write(&buf, 0, &byteCount);
&byteCount =
&in.read(&buf);
End-While;
&in.close();
&zip.flush();
&zip.close();
&file.delete();
Local string &MAIL_CC, &MAIL_TO, &MAIL_BCC,
&MAIL_SUBJECT, &MAIL_TEXT, &MAIL_FILES, &MAIL_TITLES;
Local number &MAIL_FLAGS;
&MAIL_FLAGS = 0;
/* Code new */
Local string &runcntrl_id;
&runcntrl_id = PSQUERY_AET.RUN_CNTL_ID.Value;
&oprid = PSQUERY_AET.OPRID.Value;
If &oprid = "XXXXX" Then
SQLExec("SELECT EMAIL_LIST FROM PS_UC_RNCTRL_EMAIL where
RUNCONTROLID = :1", &runcntrl_id, &MAIL_TO);
Else
SQLExec("select
emailid from PSOPRDEFN where OPRID =:1", &oprid, &MAIL_TO);
End-If;
/* Code new */
&MAIL_CC = "";
&MAIL_BCC = "";
&MAIL_TEXT = &query;
&MAIL_FILES = &fileout;
&MAIL_TITLES = &query | "-" | &PI |
".zip";
&MAIL_SUBJECT = &query;
&RET = SendMail(&MAIL_FLAGS, &MAIL_TO,
&MAIL_CC, &MAIL_BCC, &MAIL_SUBJECT, &MAIL_TEXT,
&MAIL_FILES, &MAIL_TITLES);
If &RET <> 0 Then
MessageBox(0,
"", 0, 0, "Sending Email Failed, Email IDs are " | &RET);
Else
MessageBox(0,
"", 0, 0, "Succesfuly sent Emails to following Email IDs "
| &RET);
End-If;
No comments:
Post a Comment