# Write to file in Report schedule action runscipt

**URL:** <https://forum.inductiveautomation.com/t/write-to-file-in-report-schedule-action-runscipt/18563>\
**Category:** Ignition\
**Tags:** python, ignition79, scripting\
**Created:** [June 21, 2018, 3:15pm UTC](https://forum.inductiveautomation.com/t/write-to-file-in-report-schedule-action-runscipt/18563 "2018-06-21T15:15:44Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![m.edmonson](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@m.edmonson](https://forum.inductiveautomation.com/u/m.edmonson)\
**Post date:** [June 21, 2018, 3:15pm UTC](https://forum.inductiveautomation.com/t/write-to-file-in-report-schedule-action-runscipt/18563/1 "2018-06-21T15:15:44Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [June 21, 2018, 3:20pm UTC](https://forum.inductiveautomation.com/t/write-to-file-in-report-schedule-action-runscipt/18563/2 "2018-06-21T15:20:23Z")

</div>

Why not just use [`system.file.writeFile`](https://docs.inductiveautomation.com/display/DOC79/system.file.writeFile)? You can provide the report bytestream directly.

---

<div class="post-metadata">

**Author:** ![m.edmonson](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@m.edmonson](https://forum.inductiveautomation.com/u/m.edmonson)\
**Post date:** [June 21, 2018, 3:24pm UTC](https://forum.inductiveautomation.com/t/write-to-file-in-report-schedule-action-runscipt/18563/3 "2018-06-21T15:24:34Z")

</div>

worked like a charm. i knew there was an easy way to do it.  
Thank You!

---

<div class="post-metadata">

**Author:** ![m.edmonson](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@m.edmonson](https://forum.inductiveautomation.com/u/m.edmonson)\
**Post date:** [June 21, 2018, 3:27pm UTC](https://forum.inductiveautomation.com/t/write-to-file-in-report-schedule-action-runscipt/18563/4 "2018-06-21T15:27:18Z")

</div>

Here’s a screen shot of the code if anyone needs it.

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/2/20c1fafc71e52652a97a3b24547e85b399e1b3d3.PNG)

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [June 22, 2018, 2:44pm UTC](https://forum.inductiveautomation.com/t/write-to-file-in-report-schedule-action-runscipt/18563/6 "2018-06-22T14:44:55Z")

</div>

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.

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/c/cddf898cc4e7204de663e944c54e35874f5925cd.png)

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/91f2e0f35a0041bca99214318fca44e13e9b30d4.png)

---

<div class="post-metadata">

**Author:** ![m.edmonson](https://avatars.discourse-cdn.com/v4/letter/m/8e7dd6/32.png) [@m.edmonson](https://forum.inductiveautomation.com/u/m.edmonson)\
**Post date:** [June 22, 2018, 3:05pm UTC](https://forum.inductiveautomation.com/t/write-to-file-in-report-schedule-action-runscipt/18563/7 "2018-06-22T15:05:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PerryAJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/perryaj/32/3281_2.png) [@PerryAJ](https://forum.inductiveautomation.com/u/PerryAJ)\
**Post date:** [June 22, 2018, 6:50pm UTC](https://forum.inductiveautomation.com/t/write-to-file-in-report-schedule-action-runscipt/18563/8 "2018-06-22T18:50:06Z")

</div>

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](https://docs.inductiveautomation.com/display/DOC79/Expression+Functions) provides a fairly rich set of functions/operations that enable a lot of flexibility. Definitely check it out if you’re not too familiar!

---

<div class="post-metadata">

**Author:** ![Brian\_Cockrell](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@Brian\_Cockrell](https://forum.inductiveautomation.com/u/Brian_Cockrell)\
**Post date:** [October 15, 2024, 3:03pm UTC](https://forum.inductiveautomation.com/t/write-to-file-in-report-schedule-action-runscipt/18563/9 "2024-10-15T15:03:00Z")

</div>

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.

 ![17290045329285964199024253099861](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/e/2e11fbf102a81a8b03642587ee1f4af21716d1cb.jpeg)

Am i doing something wrong. I am just a little baffled.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [October 15, 2024, 6:05pm UTC](https://forum.inductiveautomation.com/t/write-to-file-in-report-schedule-action-runscipt/18563/10 "2024-10-15T18:05:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Brian\_Cockrell](https://avatars.discourse-cdn.com/v4/letter/b/6f9a4e/32.png) [@Brian\_Cockrell](https://forum.inductiveautomation.com/u/Brian_Cockrell)\
**Post date:** [October 16, 2024, 11:10am UTC](https://forum.inductiveautomation.com/t/write-to-file-in-report-schedule-action-runscipt/18563/11 "2024-10-16T11:10:37Z")

</div>

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.
