How to log multiple tag when one tag value change?

Hello Friends,

I want to log multiple tags using of the one tag value change.

For example : 100 tags log when the tag_1 value change.

Thanks & Regards,

Govind Suthar

I believe that's a typical use case for transaction groups.

https://docs.inductiveautomation.com/display/DOC81/Understanding+Transaction+Groups#UnderstandingTransactionGroups-TriggerSettings

1 Like

Hello dear,

Thanks for reply,

Yes, I already tried with transaction groups. But, i want to log using tag historian module.

That seems like the wrong tool for the job, but I guess you can script it with system.tag.storeTagHistory when your monitored tag change.
Also, when you have requirements like this, please explain them upfront. Though if that's not a requirement but simply something you want... I suggest you reconsider and use a transaction group.

1 Like

The tag historian simply does not work that way, sorry. Use a transaction group. Or script the equivalent on a tag change event.

3 Likes

How it work through script. could explain it with example?

Sure. I would normally configure a gateway tag change event with a one-line delegation to a script library function, like so:

someScript.someFunction(initialChange, event)

Then, in the library script someScript, I'd have something like this:

from java.lang import Throwable

logger = system.util.getLogger(system.util.getProjectName() + '.' + __name__)

tagsForSomeFunction = ['path/to/tagA', 'path/to/tagB']
opcForSomeFunction = ['[device1]path/to/itemA', '[device2]path/to/itemB']
opcServer = 'Ignition OPC UA Server'

sqlForSomeFunction = """
INSERT INTO some_table (t_stamp, trigger, all_good, tag_a, tag_b, item_a, item_b)
VALUES (?, ?, ?, ?, ?, ?, ?)"""

def someFunction(initialChange, event):
	if initialChange:
		return
	t_stamp = system.date.now()
	triggerValue = event.currentValue.value
	tagQVs = system.tag.readBlocking(tagsForSomeFunction)
	opcQVs = system.opc.readValues(opcServer, opcForSomeFunction)
	
	allGood = all([qv.quality.good for qv in (tagQVs + opcQVs)])
	params = [t_stamp, triggerValue, allGood] + [qv.value for qv in (tagQVs + opcQVs)]
	try:
		rowCount = system.db.runPrepUpdate(sqlForSomeFunction, params, 'someDatabaseName')
	except Throwable, t:
		logger.warnf("Failed to insert for event=%s, values=%s", [event, repr(params)], t)
		return
	if allGood and rowCount:
		logger.tracef("Data reads and Insert success for event=%s", event)
	else:
		logger.infof("Incomplete read/insert, rowCount=%s, event=%s", rowCount, event)

Note that any constants used are assigned outside the function -- they will persist.

You are responsible for creating the target table and any indices it will need.