How to email and move a UBEs CSV/PDFs file anywhere you like

johndanter

johndanter

Legendary Poster
Hi folks,

I've been asked to do 2 handy things lately, 1) email a UBEs output and 2) get the UBEs output from the print Q ready for FTP. (by moving a designated folder)
I have this working and thought I'd share my code here in case someone else ever gets asked the same thing in the future.

EVENTS
UBE: R554111CM
Event: End Report (future)
Event GUID: c606bb92-c827-45f3-ba92-a654b3e8d5b7
----------------------------------------
Event Level Variables
----------------------------------------
evt_szHostName_JOBN [JOBN]
evt_szJobDetails_FNDFUF2 [FNDFUF2]
evt_szDataSource_SRC [SRC]
evt_szInstallDir_DVAL [DVAL]
evt_szFileName_URLPATH [URLPATH]
evt_szEmailIds_VAR1 [VAR1]
evt_szEmailAddressow_EMAL [EMAL]
evt_mnAddressNumber_AN8 [AN8]
evt_mnServerJobNumber_JOBNBR [JOBNBR]
evt_B984054ServerJobNumber [JOBNBR]
evt_EmailTxtCommandString_CMDS [CMDS]
evt_FileAddress_CMDS [CMDS]
evt_PrintQueue_CMDS [CMDS]
evt_FoundationFutUse2_FNDFUF2 [FNDFUF2]
evt_Integer01 [INT01]
evt_cFileExists_EV01 [EV01]
evt_ComputerID [CTID]
evt_GTSAttachmentName_YATTNM [YATTNM]
evt_szExecuteCommand_NFLF [NFLF]
evt_szFTPCSVName_CMDS [CMDS]
evt_EmailSubject_CMDS [CMDS]
evt_ProoforFinal_DL01 [DL01]
evt_EmailFrom_HLNK [HLNK]
evt_AttachmentName_YATTNM [YATTNM]
----------------------------------------
// BEGIN: John Danter 20/06/2017 MPRJ0082.55.05 - Consigned Stock Lodz changes
// Email and FTP UBE CSV file attachment
//
// ===================================
// Filename
// FNDFUF2 is stored as a string made up of "OBJ_VERS_JOBNBR_PDF"
// ===================================
// Print Queue Address
-GTSGetPDFAddress(B550002.GTSGetPDFAddress)
VA evt_PrintQueue_CMDS [CMDS] <- szCommandString [CMDS]

(just calls C API GetPrintQueueDirectoryPathName (lpDS->szCommandString);)

// OBNM_VERS
VA evt_AttachmentName_YATTNM = concat([SL ReportName],'_')
VA evt_AttachmentName_YATTNM = concat([VA evt_AttachmentName_YATTNM],[SL VersionName])
// Job Number
-GetAuditInfo(B9800100.GetAuditInfo)
VA evt_ComputerID [CTID] <- szMachineKey [MKEY]
-GetOneWorldJobNumber(B984054.GetOneWorldJobNumber)
VA evt_ComputerID [CTID] -> szExecutionHostName [EXEHOST]
VA evt_mnServerJobNumber_JOBNBR [JOBNBR] <- mnServerJobNumber [JOBNBR]
VA evt_AttachmentName_YATTNM = concat([VA evt_AttachmentName_YATTNM],'_')
VA evt_AttachmentName_YATTNM = concat([VA evt_AttachmentName_YATTNM],[VA evt_mnServerJobNumber_JOBNBR])
VA evt_AttachmentName_YATTNM = concat([VA evt_AttachmentName_YATTNM],'_PDF')
VA evt_AttachmentName_YATTNM = rtrim([VA evt_AttachmentName_YATTNM],' ')
//
// .CSV
VA evt_FileAddress_CMDS = concat([VA evt_PrintQueue_CMDS],[VA evt_AttachmentName_YATTNM])
VA evt_FileAddress_CMDS = concat([VA evt_FileAddress_CMDS],'.csv')
//
// Subject
VA evt_EmailSubject_CMDS = concat('Weekly Consumption Report ',date_today( ) )
VA evt_EmailSubject_CMDS = concat([VA evt_EmailSubject_CMDS],' ')
VA evt_EmailSubject_CMDS = concat([VA evt_EmailSubject_CMDS],[RV ProofOrFinal_DL01])
//
// Body text
-If PO mnSupplierNumber_AN8 [AN8] is greater than "0"
| VA evt_EmailTxtCommandString_CMDS = concat("Weekly Consumption Report for Vendor ",[PO mnSupplierNumber_AN8])
| VA evt_EmailTxtCommandString_CMDS = concat([VA evt_EmailTxtCommandString_CMDS]," Period ending: ")
| VA evt_EmailTxtCommandString_CMDS = concat([VA evt_EmailTxtCommandString_CMDS],[SL DateToday])
| VA evt_EmailTxtCommandString_CMDS = concat([VA evt_EmailTxtCommandString_CMDS], ' ')
| VA evt_EmailTxtCommandString_CMDS = concat([VA evt_EmailTxtCommandString_CMDS],[RV ProofOrFinal_DL01])
-Else
| VA evt_EmailTxtCommandString_CMDS = concat("Weekly Consumption Report for Multiple Vendors",' ')
| VA evt_EmailTxtCommandString_CMDS = concat([VA evt_EmailTxtCommandString_CMDS]," Period ending: ")
| VA evt_EmailTxtCommandString_CMDS = concat([VA evt_EmailTxtCommandString_CMDS],[SL DateToday])
| VA evt_EmailTxtCommandString_CMDS = concat([VA evt_EmailTxtCommandString_CMDS], ' ')
| VA evt_EmailTxtCommandString_CMDS = concat([VA evt_EmailTxtCommandString_CMDS],[RV ProofOrFinal_DL01])
End If
//
// Attachment name
VA evt_GTSAttachmentName_YATTNM = concat([VA evt_AttachmentName_YATTNM],'.csv')
//
-CheckForFile(B0500725.CheckForFile)
VA evt_Integer01 [INT01] <- nReturnCode [INT01]
VA evt_FileAddress_CMDS [CMDS] -> szFullFileName [MMFN]
-If VA evt_Integer01 [INT01] is equal to "1"
| VA evt_cFileExists_EV01 [EV01] = "1"
-Else
| VA evt_cFileExists_EV01 [EV01] = <Blank>
End If
//
// ===================================
// Email CSV File
// ===================================
-If PO szEmailAddressCSV_EMAL [EMAL] is greater than <Blank>
| -If SL LoginEnvironment is equal to ("JPD900","PD900")
| | VA evt_EmailFrom_HLNK [HLNK] = "[email protected]"
| -Else
| | -If SL LoginEnvironment is equal to ("JUT900","UT900")
| | | VA evt_EmailFrom_HLNK [HLNK] = "[email protected]"
| | -Else
| | | -If SL LoginEnvironment is equal to ("JPY900","PY900")
| | | | VA evt_EmailFrom_HLNK [HLNK] = "[email protected]"
| | | -Else
| | | | -If SL LoginEnvironment is equal to ("DV900","JDV900")
| | | | | VA evt_EmailFrom_HLNK [HLNK] = "[email protected]"
| | | | End If
| | | End If
| | End If
| End If
| -EmailMergeLetter(B0500725.EmailMergeLetter)
| VA evt_EmailFrom_HLNK [HLNK] -> szFrom [HLNK]
| PO szEmailAddressCSV_EMAL [EMAL] -> szTo [HLNK]
| VA evt_FileAddress_CMDS [CMDS] -> szSubject [CMDS]
| VA evt_EmailTxtCommandString_CMDS [CMDS] -> szMessageTextChar256 [CMDS]
| VA evt_cFileExists_EV01 [EV01] -> cIncludeAttachmentFlag01 [EV01]
| VA evt_FileAddress_CMDS [CMDS] -> szNameOfAttachmentFile [HLNK]
| VA evt_GTSAttachmentName_YATTNM [YATTNM] -> szAttachmentDisplayText [CMDS]
End If
//
// ===================================
// FTP CSV file
// ===================================
-If PO cProofOrFinal1_EV01 [EV01] is equal to "1"
And PO szFTPFolderLocation_CMDS [CMDS] is greater than <Blank>
| // Construct complete destination FTP folder and filename address
| VA evt_szFTPCSVName_CMDS = concat([PO szFTPFolderLocation_CMDS],[VA evt_GTSAttachmentName_YATTNM])
| //
| VA evt_szExecuteCommand_NFLF = concat('cp ' , [VA evt_FileAddress_CMDS])
| VA evt_szExecuteCommand_NFLF = concat([VA evt_szExecuteCommand_NFLF],' ')
| VA evt_szExecuteCommand_NFLF = concat([VA evt_szExecuteCommand_NFLF],[VA evt_szFTPCSVName_CMDS])
| //
| -ExecuteExternalProgram(B34A1030.ExecuteExternalProgram)
| VA evt_szExecuteCommand_NFLF [NFLF] -> szCommandLine [NFLF]
End If


Note this won't work locally as you can't get the job number using B984054.

Hope it's of use to someone.

Have a good weekend

John
 

Attachments

  • Email FTP UBE output.txt
    7.9 KB · Views: 108
Last edited:
Yes mate
Very simple, I made a comment for you rather than attaching the file

(just calls C API GetPrintQueueDirectoryPathName (lpDS->szCommandString)
 
Back
Top