Write to Text Fields with Scripting

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?

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

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 = ""
1 Like

Thanks!

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 = ""