Hi I would like to send a report that looks like below,
Parameters used: StartDate, EndDate,iProcess
I want the screen to append for iProcess from 1 to 5 and send this report over a mail.
I am triggering this function via memory tag with script below,
if currentValue.value and not initialChange:
import system
# Get logger
logger = system.util.getLogger("Report")
# Define report path and date parameters
reportPath = "Graphical Loss Report"
StartDate = system.tag.readBlocking("[.]../../Global/ShiftStart")[0].value
EndDate = system.tag.readBlocking("[.]../../Global/ShiftEnd")[0].value
# Reset trigger tag
system.tag.writeBlocking("[.]ShiftNotificationTrigger", [0])
# Initialize flag variable to track exceptions
hasExceptions = False
# Initialize report bytes
reportBytes = bytearray()
# Loop through iProcess values and add each process page to report
for iProcess in range(1, 5):
logger.info("Adding process page for iProcess %d" % iProcess)
# Set report parameters and get process page bytes
params = {"StartDate": StartDate, "EndDate": EndDate, "iProcess": iProcess}
try:
processBytes = system.report.executeReport(
path=reportPath,
project="XYZ",
parameters=params,
fileType="pdf"
)
except Exception as e:
# Catch report generation exceptions and set flag variable
logger.error("Error generating report for iProcess %d: %s" % (iProcess, str(e)))
hasExceptions = True
continue
# Append process page bytes to report bytes
reportBytes.extend(processBytes)
if hasExceptions:
# Send email indicating that report generation failed for one or more iProcess values
system.net.sendEmail(
smtpProfile="XYZ",
fromAddr="ignition-noreply@xxx.tech",
to=[ "xysz.com" ],
subject="Combined Report for all iProcess - Error",
body="Failed to generate report for one or more iProcess values.",
)
else:
# Send email with report bytes
system.net.sendEmail(
smtpProfile="XYZ",
fromAddr="ignition-noreply@xxx.tech",
to=[ "xysz.com" ],
subject="Combined Report for all iProcess",
body="Please find attached the combined report for all iProcess.",
attachments=[("CombinedReport.pdf", reportBytes)]
)
logger.info("Combined report sent")
I am getting a mail without attachment.
IDK what is missed/wrong here.
Kindly assist in resolving this