Write to file in Report schedule action runscipt

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”)

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.


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