# \[SOLVED\] Saving File by script whitout ask user

**URL:** <https://forum.inductiveautomation.com/t/solved-saving-file-by-script-whitout-ask-user/68108>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [December 30, 2022, 9:44pm UTC](https://forum.inductiveautomation.com/t/solved-saving-file-by-script-whitout-ask-user/68108 "2022-12-30T21:44:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Esmeralda\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Esmeralda\_Lopez](https://forum.inductiveautomation.com/u/Esmeralda_Lopez)\
**Post date:** [December 30, 2022, 9:44pm UTC](https://forum.inductiveautomation.com/t/solved-saving-file-by-script-whitout-ask-user/68108/1 "2022-12-30T21:44:30Z")

</div>

Hello everyone, I have this code:

I want to save the file whitout asking to user, just save it directly when a tag change

```auto
table =event.source.parent.getComponent("tblEstadisticasPedidos")
table2=event.source.parent.getComponent("tblEstadisticasLineas")
tag='[default]app_tags/Componentes/ArranquePedidos/Counter_Ready'

from com.inductiveautomation.ignition.common import BasicDataset
dataset= BasicDataset(table.data)
dataset2= BasicDataset(table2.data)
dataset.setColumnNames(["Fecha","Confirmacion","No. ","No. 2","No. 3"])
dataset2.setColumnNames(["No. ","Nombre ","Codigo "])

if tag.value==10:
     sp= system.dataset.dataSetToExcel(1,[dataset,dataset2])
     filePath = system.file.writeFile('C:\\Users\\username\\Desktop\\document.xls',sp)

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [December 31, 2022, 3:28pm UTC](https://forum.inductiveautomation.com/t/solved-saving-file-by-script-whitout-ask-user/68108/2 "2022-12-31T15:28:44Z")

</div>

You will need to use system.tag.readblocking to get the tag value. Otherwise, I don't see anything else in your code that would prevent a file from being created without a user prompt. Here is your code, modified in a way that would work:

```auto
table =event.source.parent.getComponent("tblEstadisticasPedidos")
table2=event.source.parent.getComponent("tblEstadisticasLineas")
tagPath ='[default]app_tags/Componentes/ArranquePedidos/Counter_Ready'
tag = system.tag.readBlocking(tagPath)

from com.inductiveautomation.ignition.common import BasicDataset
dataset= BasicDataset(table.data)
dataset2= BasicDataset(table2.data)
dataset.setColumnNames(["Fecha","Confirmacion","No. ","No. 2","No. 3"])
dataset2.setColumnNames(["No. ","Nombre ","Codigo "])

if tag[0].value==10:
	sp = system.dataset.dataSetToExcel(True,[dataset,dataset2])
	filepath = system.file.writeFile('C:/Users/username/Desktop/document.xls', sp)

```

**Edit:** It occurs to me that the other part of this question could be where to fire the script from. Since this is relying on data from components within a client window, then the tag value would probably need to be bound to some component in the window itself. Then, a propertyChange event handler could be used to get this done. Here is an example with the tag value being bound to the _Value (integer)_ property of a numeric text field:

```auto
if event.propertyName == 'value':
	table =event.source.parent.getComponent("tblEstadisticasPedidos")
	table2=event.source.parent.getComponent("tblEstadisticasLineas")
	tagValue = event.source.intValue
	
	from com.inductiveautomation.ignition.common import BasicDataset
	dataset= BasicDataset(table.data)
	dataset2= BasicDataset(table2.data)
	dataset.setColumnNames(["Fecha","Confirmacion","No. ","No. 2","No. 3"])
	dataset2.setColumnNames(["No. ","Nombre ","Codigo "])
	
	if tagValue == 10:
		sp = system.dataset.dataSetToExcel(True,[dataset,dataset2])
		filepath = system.file.writeFile('C:/Users/username/Desktop/document.xls', sp)

```

With this approach, it isn't necessary to read the tag, but rather just the component property itself.

The other thing that is perhaps missing from the code is a way to dynamically obtain the correct path to the current user's desktop. I typically do this with `getPass`.

Simply add this to the beginning of you code:

```auto
import getpass
username = getpass.getuser()

```

Then, change your filepath to this:

```auto
filepath = 'C:/Users/' + username + '/Desktop/document.xls'
system.file.writeFile(filepath, sp)
```

---

<div class="post-metadata">

**Author:** ![Esmeralda\_Lopez](https://avatars.discourse-cdn.com/v4/letter/e/fbc32d/32.png) [@Esmeralda\_Lopez](https://forum.inductiveautomation.com/u/Esmeralda_Lopez)\
**Post date:** [January 5, 2023, 7:15pm UTC](https://forum.inductiveautomation.com/t/solved-saving-file-by-script-whitout-ask-user/68108/3 "2023-01-05T19:15:02Z")

</div>

Hi, thank you so much, this worked for me and thank you for your time
