Automatically Updating Web Dev

Hello,

I am using the Reports module to update a pdf report every hour. I am also using a Perspective page with a button to open the pdf file which is stored in the Web Dev module. I want the Web Dev to update the file automatically when the Report module generates a new report. Can we do that?

Hi,

You could browse every file in your folder and get the lastest report path. Then return the file with the following code in the webdev python ressourse GET.

path = .............
bytes = system.file.readFileAsBytes(path)
return {'bytes': bytes, 'contentType' : 'application/pdf'}

Are you overwriting an existing file in a certain directory, or saving with different timestamps?
Do you actually need to save these files in a directory, or can your Webdev endpoint just generate the report programatically?

Currently, I am overwriting the report every hour. I thought that Web Dev would update to the newest version but it doesn’t. I need the report to be saved in a pdf format and opened in a new tab when I press on a certain button in Perspective View.
I am not generating the Web Dev programmatically, although I tried but failed.

Use a mounted folder resource type, not a file. File resources are copied into the project, so they’re static once configured. A mounted folder is ‘dumb’ - it will always attempt to retrieve whatever path it’s given.

I did that too. When the webpage opens (the tab that should be the pdf file) it says not found.

Then that’s the problem to address. You’re using the correct filename? Are you sure your gateway has access to the folder to read?

I mount the folder (the folder is on the network not on my local device but the gateway has access to that folder because I can post the report on that folder)
Right click on the button --> Configure Event --> Mouse Event on Click --> Add Navigation --> Url --> paste the mounted path of the folder/myfile

You can have the webDev as a python resource and execute the report and return it.

Line = 1
pName = 'CurrentPlant'
sDate = system.date.addHour(-1,system.date.now())
eDate = system.date.now()
dbName = 'Default'
overrides = {"PName":pName,'SDate':sDate,'EDate':eDate,'dbName':dbName,'Line':line}
bytesArray = system.report.executeReport(path="Delay Report", project="ProjectName", parameters=overrides, fileType="pdf")
return {'contentType':'application/pdf','bytes':bytesArray}
1 Like

should I call the python resource when pressing the button as navigate to the mounted path?

Kind of.
A python resource ends up as a URL.
You can put the URL as the PDF source
http://YourGatewayAddress:8088/main/system/webdev/YourProjectName/PythonResourceName

I can manually press on the >> button in the Report Module and see the file updated. Now with your code, I am getting “Report Path cannot be found”

Did you edit the bytesArray line for the proper parameters?

yes. I tried the network address of the folder, and I tried the mount path of the same folder. Both failed

Is there a way to code a Web Dev File Resource creation?

The path in the bytesArray is the path to the report INSIDE the project.
So if it is in the reports folder as Report1 then in the bytesArray it would be “Report1”
If it’s in a folder under Reports then it would be “FolderName/Report1”

You are executing the report, not opening an actual file name.
https://docs.inductiveautomation.com/display/DOC79/system.report.executeAndDistribute

1 Like

YES! IT WORKED! Thank you so much!