Writing dataset to memory tag with script issue

Hello everyone,
I need some help with my script, it was working perfectly prior the upgrade that we made to our Ignition Gateway. I was using the following code:

headers = [“N NCP,Titulo”,“Fecha de efectividad”,“Linea de ensamble”,“Estaciones afectadas”]
data5 = system.dataset.toDataSet(headers,ncpsT5)
system.tag.write(“[default]OpAgricolas/SharepointIntegration/NCPsT5000”,data5)

I change it for this because this stopped working:

headers = [“N NCP,Titulo”,“Fecha de efectividad”,“Linea de ensamble”,“Estaciones afectadas”]
data5 = system.dataset.toDataSet(headers,ncpsT5)
system.tag.writeBlocking(“[default]OpAgricolas/SharepointIntegration/NCPsT5000”,data5)

The code executes just fine from the “script console” but is doing nothing with the tag it keeps being empty.

Any advice? what I am missing?

Thanks in advance!

How did you define this variable? If its an empty list I would expect an empty dataset.

Supply proper lists of paths and values to writeBlocking. Capture the return value (a list of status codes). Examine that return value to determine what went wrong. (In a tag event, you will need to use a logger from system.util.getLogger to report to the gateway log.)

1 Like

Hello! thank you for answering. So I checked that by printing the variable and I do get rows and columns from it. However, since there is nothing to hide with my code:

def createDataset(SPlist):
	import datetime
	ncpsT5 =[]
	ncpsT6 =[]
	ncpsC = []
	ncpsP = []
	estaciones = []
	for ncp in SPlist:
		date = datetime.datetime.strptime(ncp['Fechadeefectividad'],"%Y-%m-%dT%H:%M:%SZ")
		#print([ncp['ID'],ncp['Title'],date,ncp['LineadeEnsamble'],ncp['Estaci_x00f3_n']])
		if (date.isocalendar()[1] == datetime.datetime.today().isocalendar()[1]) and (date.isocalendar()[0] == datetime.datetime.today().isocalendar()[0]):
			date = date.strftime('%d/%m/%Y')
			if ncp['LineadeEnsamble'] == "Tractores Utilitarios":
				oneRow = [ncp['ID'],ncp['Title'],date,ncp['LineadeEnsamble'],ncp['Estaci_x00f3_n']] #ncp['Fechadeefectividad']
				ncpsT5.append(oneRow)
				for est in ncp['Estaci_x00f3_n']:
					oneRow = [ncp['ID'],ncp['LineadeEnsamble'],est]
					estaciones.append(oneRow)
			elif ncp['LineadeEnsamble'] == "Tractores Medianos y Grandes":
				oneRow = [ncp['ID'],ncp['Title'],date,ncp['LineadeEnsamble'],ncp['Estaci_x00f3_n']] #ncp['Fechadeefectividad']
				ncpsT6.append(oneRow)
				for est in ncp['Estaci_x00f3_n']:
					oneRow = [ncp['ID'],ncp['LineadeEnsamble'],est]
					estaciones.append(oneRow)
			elif ncp['LineadeEnsamble'] == "Cosechadoras":
						oneRow = [ncp['ID'],ncp['Title'],date,ncp['LineadeEnsamble'],ncp['Estaci_x00f3_n']] #ncp['Fechadeefectividad']
						ncpsC.append(oneRow)
						for est in ncp['Estaci_x00f3_n']:
							oneRow = [ncp['ID'],ncp['LineadeEnsamble'],est]
							estaciones.append(oneRow)
			elif ncp['LineadeEnsamble'] == "Plataformas":
										oneRow = [ncp['ID'],ncp['Title'],date,ncp['LineadeEnsamble'],ncp['Estaci_x00f3_n']] #ncp['Fechadeefectividad']
										ncpsP.append(oneRow)
										for est in ncp['Estaci_x00f3_n']:
											oneRow = [ncp['ID'],ncp['LineadeEnsamble'],est]
											estaciones.append(oneRow)
	headers = ["N NCP","Titulo","Fecha de efectividad","Linea de ensamble","Estaciones afectadas"]
	data5 = system.dataset.toDataSet(headers,ncpsT5)
	system.tag.writeBlocking(["[default]OpAgricolas/SharepointIntegration/NCPsT5000"],data5)
	data6 = system.dataset.toDataSet(headers,ncpsT6)
	system.tag.writeBlocking("[default]OpAgricolas/SharepointIntegration/NCPsT6000",data6)
	dataC = system.dataset.toDataSet(headers,ncpsC)
	system.tag.writeBlocking("[default]OpAgricolas/SharepointIntegration/NCPsCosechadoras",dataC)
	dataP = system.dataset.toDataSet(headers,ncpsP)
	system.tag.writeBlocking("[default]OpAgricolas/SharepointIntegration/NCPsPlataformas",dataP)
	headers2 = ["NCP","Linea de ensamble","Estaciones"]
	#print(len(estaciones))
	data = system.dataset.toDataSet(headers2,estaciones)
	system.tag.writeBlocking("[default]OpAgricolas/SharepointIntegration/NCPsEstaciones",data)

Just a couple of things

  1. use this
    image
    button to paste code in or triple backticks

```

if something:
    print 'hi'

```
It applies python syntax highlighting which makes it much easier to read and keeps your tabs.

  1. I know its not related to your question, but don’t use datetime, use the Ignition built-in date functions from system.date.* There’s a variety of reasons to do this, but as a general rule of thumb, look to see if there’s a built-in system.* function to do what you need to do before relying on a jython implementation as some are just bad.

  2. It’s a bit hard to read your code however it seems like you are populating ncpsT5 with some data so I will assume it’s not an issue of you writing blank rows (though you can print or log the value of ncpsT5 before your tag write to confirm this) so it may be an issue with the write itself. In this case, do what @pturmel suggested and verify the result of the write.

You would need to do something like

results = system.tag.writeBlocking(“[default]OpAgricolas/SharepointIntegration/NCPsT5000”,data5)
for result in results:
	print result.diagnosticMessage

and see what it says. If you are having a tag write error this should tell you whats going wrong.

1 Like

Thank you so much for the advice! I fixed the format in the original post (sorry for that). I followed @pturmel advise and finally I have an error to work with. However, I do not get why it is happening:

class org.python.core.PyList: Invalid DataType for Dataset.

It's happening because we don't allow Datasets with arbitrary contents to be written to Dataset tags, because these tags need their value persisted. If the Dataset will be written to a tag you need to stick more-or-less to column types that are similar to the Ignition tag datatypes available.

1 Like

image
Solved!!! for some reason a column that was always there was causing this issue. Thank you everyone!!!

1 Like