Send Email Script with parameter not working

I am currently trying to have an email sent if a tag reads in between certain values. I also want the email to contain the machine number that the tags are coming from. I have the machine number set as one of the parameters of the tags. This is the current code I am working with:

if currentValue.value > 5 and currentValue.value < 10 or currentValue.value > 18 and currentValue.value < 20:
				
				body = '{ENumber}'  + "had a yellow zone resul of:" + currentValue.value
				rec = ['ryan.craig@colder.com']
				
				system.net.sendEmail("smtp.dovercorporation.com", "BurstTesters@colder.com", "Burst Tester Caution", body, 0 , rec)

which is giving me this error:

([default]E398/E398/Test2BurstFinal, valueChanged) Error executing tag event script: Traceback (most recent call last): File "tagevent:valueChanged", line 26, in valueChanged TypeError: cannot concatenate 'str' and 'float' objects

I also tried this code:


			if currentValue.value > 5 and currentValue.value < 10 or currentValue.value > 18 and currentValue.value < 20:
				
				body = str({ENumber})  + "had a yellow zone resul of:" + currentValue.value
				rec = ['ryan.craig@colder.com']
				
				system.net.sendEmail("smtp.dovercorporation.com", "BurstTesters@colder.com", "Burst Tester Caution", body, 0 , rec)
	

which is giving me this error:

([default]E398/E398/Test2BurstFinal, valueChanged) Error executing tag event script: Traceback (most recent call last): File "tagevent:valueChanged", line 26, in valueChanged NameError: global name 'E398' is not defined

Any idea how to fix this issue?

We have no way to know what line 26 is if you don't post at least 26 lines of your script :smile:

But, it's pretty much guaranteed to be this line, or a similar one earlier:

body = str({ENumber})  + "had a yellow zone resul of:" + currentValue.value

In expressions, you can just curly-braces to insert dynamic references to properties and tags. In scripting, you cannot - you are bound to the semantics of Python, because that's the language you're using.

So what you are meaning to do, I assume, is read a sibling tag ENumber, but what you are actually doing is trying to create a Python set literal with one member, the variable ENumber.... which (probably) doesn't exist in the local scope.

You need to use the system.tag.readBlocking function to read any tag from scripting. The function returns a list of qualified value objects. So the most direct translation of this line would be something like this:

qvs = system.tag.readBlocking(["[.]ENumber"])
ENumber = qvs[0].value
body = str(ENumber)  + "had a yellow zone resul of:" + currentValue.value
1 Like

Also, you need to cast currentValue.value as a str, because it's apparently a float (based on your conditional checks).

body = str(ENumber)  + "had a yellow zone result of:" + str(currentValue.value)
2 Likes

My mistake, yes the script I posted was line 26. This solution seemed to do the trick, thank you!

I noticed that, as well, after I made this post. Thanks for the help!

1 Like