Can I tie the database name in a tag based script to a memory tag value?

Hello. I am currently using 8.1.17 and am using tag event scripts to write to my database. IT has informed me that we will be changing over our database with a newer one and the tables that I am currently writting to will be changed. Can i try my database name to a memory tag and use it as a variable in my update? In the script below i would like to change “Epics” to the dbConn that i have marked out in my variable list. I have tried but cannt get it to work. Any help would be greatly appreciated.

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
Fired whenever the current value changes in value or quality.

	tag: The source tag object. A read-only wrapper for obtaining tag
	tagPath: The full path to the tag (String)
	previousValue: The previous value. This is a "qualified value", so it
	               has value, quality, and timestamp properties.
	currentValue: The current value. This is a "qualified value", so it has
	              value, quality, and timestamp properties.
	initialChange: A boolean flag indicating whether this event is due to
	               the first execution or initial subscription.
	missedEvents: A flag indicating that some events have been skipped due
	              to event overflow.
if previousValue.value != currentValue.value and initialChange == False:
	plant ="[default]CRP Checklist/QueryBuilingTags/Plant").value
Furnace"[default]CRP Checklist/QueryBuilingTags/Furnace").value
line ="[default]CRP Checklist/QueryBuilingTags/Line").value
CheckListName ="[default]CRP Checklist/QueryBuilingTags/CheckListName").value
TagName ="[default]CRP Checklist/PCheck2Value.Name").value
TagValue ="[default]CRP Checklist/PCheck2Value").value
TagDataType ="[default]CRP Checklist/QueryBuilingTags/TagDataType").value
DateEntered ="[default]CRP Checklist/QueryBuilingTags/DateEntered").value
ScheduledTime ="[default]CRP Checklist/PCheck2Time").value
ActualTime ="[default]CRP Checklist/PCheck2Value.Timestamp").value
#bdConn ="[default]CRP Checklist/QueryBuilingTags/Database").value

system.db.runPrepUpdate("INSERT INTO foy.SCM_Checklist (PlantID, Furnace, Line, CheckListName, TagName, TagValue, TagDataType, DateEntered, ScheduledTime, ActualTime) VALUES (?,?,?,?,?,?,?,?,?,?)",[plant, Furnace, line, CheckListName, TagName, TagValue, TagDataType, DateEntered, ScheduledTime, ActualTime],"Epics")

What have you tried?

Pssst! Please edit your post to format your script.

Click the pencil to edit, then use your mouse to select everything from the def to the end of your script, then click the “preformatted text” button, that looks like this: </>.

Typo… working now. Thank you though guys.

1 Like