Hello, I would like to update (add a row) to my tag dataset.
I'am using this fonction : system.tag.writeBlocking(self.view.params.tagPath, self.view.params.listZone)
When I try use this function, the old value on the dataset is droped
Hello, I would like to update (add a row) to my tag dataset.
I'am using this fonction : system.tag.writeBlocking(self.view.params.tagPath, self.view.params.listZone)
When I try use this function, the old value on the dataset is droped
The function requires a list of tag paths and a list of values. Try:
system.tag.writeBlocking([self.view.params.tagPath], [self.view.params.listZone])
Use system.dataset.addRows() first, then write back to the tag.
Do you really need a dataset for just one column ?
yes for one column
I can see there's only one column, my question was: do you NEED a dataset ? Wouldn't an array be enough ?
No, could very easily be an array type tag. To each their own.
Follow these steps.
1.) Read in the tag
2.) Add the row
3.) Write out the new Value.
Be sure that you write the entire dataset to the tag value, as opposed to just a single row, column pair.
#read in the dataset from the tag.
ds = system.tag.readBlocking([self.view.params.tagPath])[0].value
#add the row to the dataset
ds = system.dataset.addRows(ds,[[self.view.params.listZone]])
#write out the new value
system.tag.writeBlocking([self.view.params.tagPath],[ds])
thank you, it work
I needed a dataset, not array
A dataset, with 1 column is just an array with extra baggage. Are you sure you needed a dataset?
yes I'am sure I need dataset. there is the solution
#Update Device dataset
#read in the dataset from the tag.
DevicePath = self.view.params.tagPath
dsDevice = system.tag.readBlocking([DevicePath])[0].value
#add the row to the dataset
dsDevice = system.dataset.addRows(dsDevice,[[self.view.params.idZone]])
#write out the new value
system.tag.writeBlocking([self.view.params.tagPath],[dsDevice])
#update zone Dataset
#add info for zone
zonePath = "[tagXX]Site"+str(self.view.params.idSite)+"/Building"+str(self.view.params.idBuilding)+"/Zone/Zone"+str(self.view.params.idZone)+"/listDevice"
dsZone = system.tag.readBlocking([zonePath])[0].value
dsZone = system.dataset.addRows(dsZone,[[self.view.params.idDevice]])
system.tag.writeBlocking([zonePath],[dsZone])
Now, When I add a value, if the value exists on the dataset, I would like to avoid redundancy of values ββin the dataset.
Nothing in that code, indicates the need for a dataset. Everything you're doing could be easily accomplished with a List (a.k.a array). The dataset is only adding overhead. Oh well, you do you.
To prevent duplicates in the column you will need to loop through the column and verify that value doesn't exist. The easiest way to do that is to convert the column to a list.
#Update Device dataset
#read in the dataset from the tag.
DevicePath = self.view.params.tagPath
dsDevice = system.tag.readBlocking([DevicePath])[0].value
#verify if value already exists, if not then add row and write value
if not self.view.params.idZone in ds.getColumnAsList(0):
#add the row to the dataset
dsDevice = system.dataset.addRows(dsDevice,[[self.view.params.idZone]])
#write out the new value
system.tag.writeBlocking([self.view.params.tagPath],[dsDevice])
#update zone Dataset
#add info for zone
#use string.format
zonePath = "[tagXX]Site{0}/Building{1}/Zone/Zone{2}/listDevice".format(self.view.params.idSite,self.view.params.idBuilding,self.view.params.idZone)
dsZone = system.tag.readBlocking([zonePath])[0].value
dsZone = system.dataset.addRows(dsZone,[[self.view.params.idDevice]])