Perspective readAsync scoping

Is it possible to retain the perspective session scope in the system.tag.readAsync callback function?

In this case, I am reading a tag and trying to call the system.perspective.* functions but I keep getting an error because there is not a session attached to the thread. Below is the test script I have on a button.

def runAction(self, event):
	import system
	
	def callBack(aync):
		path = '[]SITE/Anodizing/Crew/Load Crew/Crew/Crew Info'
		data=aync[0].value
		for row in range(data.getRowCount()):
			if data.getValueAt(row,0)==self.view.params.Name and data.getValueAt(row,1)==self.view.params.EmployeeID:
				data1=system.dataset.deleteRow(data, row)
				system.tag.writeBlocking(path, data1)	
				system.perspective.closePopup(id='abrR7MU8')	
				
				
	system.tag.readAsync(['[MES_SITE_ASSET]SITE/Anodizing/Crew/Load Crew/Crew/Crew Info'], callBack)

Obviously this is a simple case where readBlocking is probably the best approach, but it got me thinking about this and if it is possible.

I don't know what the problem is but why have you got import system in there? The system functions are automatically available. They're built-in.

It was a carry-over from some other testing I was trying based on another thread. I just forgot to delete it out.

You can capture values from the outer scope when you define a function, by using default arguments:

def runAction(self, event):
	
	def callBack(aync, sessionId=self.session.id, pageId=self.page.id):
		path = '[]SITE/Anodizing/Crew/Load Crew/Crew/Crew Info'
		data=aync[0].value
		for row in range(data.getRowCount()):
			if data.getValueAt(row,0)==self.view.params.Name and data.getValueAt(row,1)==self.view.params.EmployeeID:
				data1=system.dataset.deleteRow(data, row)
				system.tag.writeBlocking(path, data1)	
				system.perspective.closePopup(id='abrR7MU8', sessionId=sessionId, pageId=pageId)
				
	system.tag.readAsync(['[MES_SITE_ASSET]SITE/Anodizing/Crew/Load Crew/Crew/Crew Info'], callBack)