Report overwritten solution

Hi,
I have report triggered by PLC tag indicating that the process is over. Usually there might 7-8 triggers per shift. The report is executed and saved in the directory for that purpose, but every new generated report overwrites the previous one, since they have the same name. I was wondering what workaround to find, any ideas?

Put the timestamp with minutes and seconds into the filename?

2 Likes

If the report name is, for example, MachineNo1, how the new name with the timestamp will look like?

You can format it as you choose;

e.g. MachineNo1_20210623_17_01_03.PDF

I meant how to include the timestamp like variable in my script?

Use a fileName parameter in the settings

# Executes and distributes the report to save a PDF
now = system.date.now()
date = system.date.format(now , "yyyy-MM-dd HH:mm:ss")
fileName = "MachineNo1 _%s" % date
settings = {"path":"C:\\Ignition Reports", "fileName":fileName, "format":"pdf"}
system.report.executeAndDistribute(path="My Report Path", project="My Project", action="save", actionSettings=settings)
2 Likes

Use system.date.now and format it before adding to the filename

from the manual

# Executes and distributes the report to save a PDF
settings = {"path":"C:\\Ignition Reports", "fileName":"Report.pdf", "format":"pdf"}
system.report.executeAndDistribute(path="My Report Path", project="My Project", action="save", actionSettings=settings)
3 Likes

@Matrix_Engineering LOL, beat you by mere seconds :slight_smile:

Thanks a lot, guys!

There is a small Python syntax issue in your script, dkhayes117, and I could not find solution.
image
system.report.executeAndDistribute accepts only arguments in quotes (" ") after β€œfileName”:, but then logically the report name stops to be variable.

you sure you did this?

Yes it works for me, just ran it and it produced

>>>MachineNo1_2021-06-24 08:14:32

EDIT: Make sure you use the correct variable in your settings

{ ... "fileName":fileName, ... }

If you try the 3 rows above in Script Console and print fileName, indeed error does not pop up.
But if I trigger the script, I get the error below:


if I place the fileName in quotes, I do not get error (which means the other parameters in the script are OK), but I do not get variable report name.
image

Ah hm try system.date.format(now , "yyyy-MM-dd-HH-mm-ss")
And be sure there is no space before the date.
Might be that filenames cant have β€œ:” in it

You defintly should not put quotes around fileName, cuz its a variablename not a string

1 Like

That was it! β€œ:” replaced with " - ", and issue solved.
Thank you!

1 Like

hehe forgot about that xd