By nature of invokeAsynchronous, it’s impossible to tell - all that stack trace is telling you is that there’s some issue with an attempt to invoke an asynch thread - specifically, the object being passed into system.util.invokeAsynchronous is null.
The end goal of this is to provide a summary of process activity after some period (overnight, weekly, etc.) so it was sending out an email for each process change. Possibly the whole thing should be re-worked to send only one email with a summary of all changes...
I got rid of the invokeAsynch. I was thinking the executeAndDistribute might need it to send multiple emails in a loop... Not sure.
The sendEmail function and new code (i.e. invokeAsynch) are within a for loop as mentioned in the post. Iterating through a SQL table for tank numbers & info.
for n in range(len(pyTankDS)):
tankNo = pyTankDS[n][0]
tank = 'Tank ' + tankNo
#read relevant properties from tag path
volume = str(round(system.tag.read('[default]Tank Status History/'+tank+'/Volume').value,1))
def sendEmail(tankNo=tankNo, tank = tank, volume = volume):
import system
recipients=["jane@test.com","jon@xyz.com"] #
system.report.executeAndDistribute(path="xyz", parameters = {"tankNumber":tankNo}, project="xyz", action= "email", actionSettings = {"to":recipients, "smtpServerName":"Mail Server", "from":"jon@xyz.com", "subject":tank + 'test email', "body":tank + " test " + volume})
system.util.invokeAsynchronous(sendEmail)
print 'post-email function'
system.db.runUpdateQuery('DELETE FROM tank_fills')
Changed to:
for n in range(len(pyTankDS)):
tankNo = pyTankDS[n][0]
tank = 'Tank ' + tankNo
#read relevant properties from tag path
volume = str(round(system.tag.read('[default]Tank Status History/'+tank+'/Volume').value,1))
recipients=["jane@test.com","jon@xyz.com"]
system.report.executeAndDistribute(path="xyz", parameters = {"tankNumber":tankNo}, project="xyz", action= "email", actionSettings = {"to":recipients, "smtpServerName":"Mail Server", "from":"jon@xyz.com", "subject":tank + 'test email', "body":tank + " test " + volume})
print 'post-email function'
system.db.runUpdateQuery('DELETE FROM tank_fills')
It seems the error was still coming up after I removed the invokeAsynchronous from the script.
Would it have tried to use invokeAsynchronous if it was a ‘dedicated’ thread? I switched it over to shared and will see if the error goes away.
Otherwise, I don’t see any other code that uses invokeAsynchronous. Maybe there is a scoping option somewhere else that has an invokeAsynchronous option, like an event script or such?