I’m attempting to make a script that will generate folders based off of the date to and add the actual report to the corresponding folder. However I’m having trouble writing to the actual file. I know I’m supposed to use the reportBytes argument but I’m having some trouble. Here’s what i have as far as the writing goes. The script does not give an error and does not write anywhere on my machine.
f = open(“fileName”, “w+b”)
f.seek(0)
f.write(reportBytes)
Why not just use system.file.writeFile
? You can provide the report bytestream directly.
worked like a charm. i knew there was an easy way to do it.
Thank You!
Here’s a screen shot of the code if anyone needs it.
1 Like
I’m a little confused why you’re using the RunScript action to save the file instead of just using the SaveFile action, since SaveFile will make any folders for you automatically. Perhaps the folder path and file name fields are confusing?
The final path that gets saved is just the folder path + file name, so you can include dynamic folder names in the file name editor. The action will create any needed folders for you. So in your example above, “C:\Ignition Reports” would be in the folder path field, and you current year month, day folders would be in the file name field. Attached is an example of how to set it up in SaveFile, and a picture of the nested folder structure – all the folders were created dynamically when the report was generated.
2 Likes
Kathy,
I was unaware that the save file action had this capability. I have a coding background so trying the script was a first thought compared to trying the save file action that doesn’t have a whole lot of documentation.
1 Like
It’s less a function of the Save File
action specifically, and more a product of the filename field itself being an expression. While less powerful than scripting, the expression language provides a fairly rich set of functions/operations that enable a lot of flexibility. Definitely check it out if you’re not too familiar!
1 Like
I am having an issue where the folder will be created but then the file gets an error. If i save it directly to the folder in the folder path i have no issues.
Folder path
C:\Path\ToFolder
But if i try any subfolders the folder will be created but i get an error as pictured and the file is not saved.
I have checked all the permissions and dont see an issue with them since the folders are created just not the file.
Am i doing something wrong. I am just a little baffled.
Best to start a new topic for this and not add on to a 6 year old thread that's about a different problem.
What version of Ignition are you using? What version of the reporting module?
Thank you.
I figured out the issue. It was an issue trying to save with a text box to an excel file. Once i deleted the text box it saved everywhere no problem.
1 Like