# Write to Text Fields with Scripting

**URL:** <https://forum.inductiveautomation.com/t/write-to-text-fields-with-scripting/45974>\
**Category:** Ignition\
**Created:** [April 23, 2021, 6:00pm UTC](https://forum.inductiveautomation.com/t/write-to-text-fields-with-scripting/45974 "2021-04-23T18:00:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![EduardoChega](https://avatars.discourse-cdn.com/v4/letter/e/c5a1d2/32.png) [@EduardoChega](https://forum.inductiveautomation.com/u/EduardoChega)\
**Post date:** [April 23, 2021, 6:00pm UTC](https://forum.inductiveautomation.com/t/write-to-text-fields-with-scripting/45974/1 "2021-04-23T18:00:23Z")

</div>

Hello,

I’m trying to write data to text fields via scripting, right now I have a dataset in a memory tag, and what I’m doing is that through text fields I’m able to write data to them and I added a “Save” button, that once I click it it creates a new row in the dataset and copies the information written in the Text Fields, so right now what I want to accomplish is that once I write the values to my dataset I want the text fields to become blank again.

This is the code I’m using:

| | tagPath = [default]ElCajon/Buildings/1940/Machines/FADAL4A/ProgramName/CNC Programs/ProgramList |
| --- | --- |
| | original\_dataset = system.tag.readBlocking([tagPath])[0].value |
| | ProgramNumber = self.getSibling(Program Number).props.text |
| | FileName = self.getSibling(File Name).props.text |
| | Product = self.getSibling(Product).props.text |
| | Description = self.getSibling(Description).props.text |
| | PartsExpected = self.getSibling(Parts Expected).props.text |
| | PartsExpected2 = self.getSibling(Parts Expected 2).props.text |
| | PartsExpected3 = self.getSibling(Parts Expected 3).props.text |
| | SetupTime = self.getSibling(Setup Time).props.text |
| | SetupSheet = self.getSibling(Setup Sheet).props.text |
| | new\_dataset = system.dataset.addRow(original\_dataset, [ProgramNumber, FileName, Product, Description, PartsExpected, PartsExpected2, PartsExpected3, SetupTime, SetupSheet,Eduardo Echegaray,1,system.date.now()]) |
| | system.tag.writeBlocking([tagPath],[new\_dataset]) |

Is there a way I can “refresh” the Text Fields via scripting?

---

<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:** [April 23, 2021, 6:07pm UTC](https://forum.inductiveautomation.com/t/write-to-text-fields-with-scripting/45974/2 "2021-04-23T18:07:25Z")

</div>

One option, to avoid writing all the names out 3 or more times:

```auto
tagPath = "[default]ElCajon/Buildings/1940/Machines/FADAL4A/ProgramName/CNC Programs/ProgramList"
original_dataset = system.tag.readBlocking([tagPath])[0].value
fields = [
	self.getSibling(field)
	for field in ["Program Number", "File Name", "Product", "Description", "PartsExpected", "PartsExpected2", "PartsExpected3", "SetupTime", "SetupSheet"] 
]
currentValues = [field.props.text for field in fields]
currentValues.extend(["Eduardo Echegaray", 1, system.date.now()])
new_dataset = system.dataset.addRow(original_dataset, currentValues)
system.tag.writeBlocking([tagPath],[new_dataset])

for field in fields:
	field.props.text = ""

```

---

<div class="post-metadata">

**Author:** ![EduardoChega](https://avatars.discourse-cdn.com/v4/letter/e/c5a1d2/32.png) [@EduardoChega](https://forum.inductiveautomation.com/u/EduardoChega)\
**Post date:** [April 23, 2021, 7:17pm UTC](https://forum.inductiveautomation.com/t/write-to-text-fields-with-scripting/45974/3 "2021-04-23T19:17:25Z")

</div>

Thanks!

---

<div class="post-metadata">

**Author:** ![EduardoChega](https://avatars.discourse-cdn.com/v4/letter/e/c5a1d2/32.png) [@EduardoChega](https://forum.inductiveautomation.com/u/EduardoChega)\
**Post date:** [April 23, 2021, 9:15pm UTC](https://forum.inductiveautomation.com/t/write-to-text-fields-with-scripting/45974/4 "2021-04-23T21:15:09Z")

</div>

This is how my code ended up looking and it’s working great!

tagPath = “[default]ElCajon/Buildings/1940/Machines/FADAL4A/ProgramName/CNC Programs/ProgramList”  
original\_dataset = system.tag.readBlocking([tagPath])[0].value  
columns = [self.getSibling(column) for column in [“Program Number”, “File Name”, “Product”, “Description”, “Parts Expected”, “Parts Expected 2”, “Parts Expected 3”, “Setup Time”, “Setup Sheet”, “Revision”]]  
currentValues = [column.props.text for column in columns]  
currentValues.extend(["", system.date.now()])  
new\_dataset = system.dataset.addRow(original\_dataset, currentValues)  
system.tag.writeBlocking([tagPath],[new\_dataset])

```
for column in columns:
	column.props.text = ""
```
