Good morning! Hopefully someone can assist. I have need for when a button is pressed to run a custom script that will create a CSV file in a network location that reads from an existing power table, pulls only certain information from the selected row in the power table, and write that information along with other information into a CSV.
We use a continuous transaction processor here that when a CSV file is dropped into a location, it will then log that specific information into our ERP. It has to be in a certain format so I need the CSV to read like “,(PartNumber),(qty),(date)” which can be found in the power table, but then I have some hard coded information as well that needs to be in the CSV for the ERP. So, I need to be able to modify the string in the csv file to put that information in as well. I mostly need the button to when pressed to get just specific information from the power table on the row selected and put it in the declared spots of the string to create the CSV, then to have Ignition generate the CSV. Any help would be greatly appreciated as I know zero about scripting.
Here's the general layout of what your script will probably resemble:
# Get the dataset from the Power Table
initialDataset = event.source.parent.getComponent('Power Table').data
# Do your dataset manipulation
# newDataset = ?
# Convert the new dataset to CSV format and write to a network location
csv = system.dataset.toCSV(newDataset)
filePath = "YourNetworkLocation" + "YourDesiredFilename.csv"
system.file.writeFile(filePath, csv)
O.K. so one of my columns in my power table is titled “Lot”, when I put the following in the script:
Get the dataset from the Power Table
initialDataset = event.source.parent.getComponent('Power Table').data
Do your dataset manipulation
newDataset = ({event.source.parent.getComponent('Power Table').selectedRow}"Lot"}+','+'Testing')
Convert the new dataset to CSV format and write to a network location
csv = system.dataset.toCSV(newDataset)
filePath = "C" + "results.csv"
system.file.writeFile(filePath, csv)
I’m trying to read from the selected row, in the column titled “lot” and take that data, write it into a CSV file along with some other commentary and drop it in a network location.