Writing to Client Tags from scripts

I presume to write to client tags from scripts the same scripting function holds good

system.tag.writeAsync(path, 0) where path the is [client]path for the tag

and also hope these client tags used to store properties that can be bound in components?

I am not getting values written in client tags with the above script function system.tag.writeAsync(path, 0)

From what scope are you calling it? Client tags only exist in Vision clients, and are independent per vision client, and can therefore only be accessed (read or write) from code in the specific Vision client. Not from gateway code, nor from one client to another.

Yes exactly. I am accessing them from a vision client for a dropdown component script to store a value based on a selection. I want to use this value inside a template repeater to hilight one of the templates based on the selection in the drop-down component which is outside the template repeater in the one of the main windows. So based on the selection in dropdown, I am initializing an array tag in client scope so that it affects only the client not affecting other clients.

Or is there another way to store the selection or a value based on selection into a custom property of the template repeater component etc. Any way other than using client tags?

Have you tried creating a custom property on the component?

No I just thought of using Client Tag. Let me think over it.

Client tags are most useful as bindable places to hold runtime values that are shared across many different windows, and/or need to persist when a particular window is closed. Most other needs for runtime values, whether states or intermediate calculations or static configuration information, is best served by custom properties on components or containers.

1 Like

Got it. Client Tags are more useful for Inter window parameter passing whereas custom parameters are more suitable for communication between components within a window. That makes sense. Though I guess there nothing wrong or nothing preventing us from using client-tags for communication or parameter passing between components within a window in a client!

However why I am not able to write and read values on the client tags using scripts using the system.tag.writeAsync(path, 0) or system.tag.readAsync(path) functions thru scripts!

When writing, is an error being thrown or logged?
When reading, system.tag.readAsync, by definition, requires you to pass a callback function, because you're using an async function. If you don't pass a callback, what's the point of reading the tags? Post your actual code, if possible.

Nothing preventing you, certainly. I personally would argue there's something "wrong" with it, though.
First, it's less performant than it needs to be. Marshaling data to/from tags is adding data transformations and extra steps that aren't necessary.
Second, it's "elevating" the lifecycle and scope of variables that only apply to a particular window outside of that window. When you come back to the project in six months or six years, are you going to remember why things were in client tags instead of custom properties?

Actually, I am binding a background color property of a component with the client tag, not actually reading it.

Perfect! furthermore, it violates the principle of encapsulation besides more importantly being less efficient with unnecessary and avoidable overheads.

However, the point remains why is the system.tag.writeAsync(path, 0) not working for me? Is it a [Client]path rather than [client]path?

system.tag.writeAsync(["[client]abc"], [0]) works perfectly fine for me on a button.
Post your code, or your output console logs, or something. Saying you've tried one thing (repeatedly) and it's not working isn't helping me help you.

1 Like

Yes, client tags writing is working fine just as it works with memory tag writing. I was using a single tag path as argument rather than a list of tag paths! Secondly, I changed to writeBlocking not writeAsync. Here is the code:

if event.propertyName == "selectedStringValue":
	if event.newValue != event.oldValue:
		#print event.newValue, event.oldValue
		path = ["[client]Hilight[0]"]
		val=[0]
		for i in range(20):
			path.append("[client]Hilight['+str(i+1)+']")
			val.append(0)
		#print path,val
		system.tag.writeBlocking(path,val)
		SelectedName=event.newValue
		if SelectedName=="All":
			tasks=system.db.runNamedQuery("All", {})
		else:		
			params = {"id":selectedName}
			tasks=system.db.runNamedQuery("searchAssignedToUser", params)
		NoOftasks=tasks.getRowCount()
		#print "no of tasks =", NoOftasks
		if NoOftasks > 0:
			path=[]
			val=[]
			for tsk in range(NoOftasks):
				tskNo = tasks.getValueAt(tsk,1)
				path.append("[client]Hilight["+ str(tskNo) +"]")
				val.append(1)
				#print "Task ",tskNo
			system.tag.writeBlocking(path, val)

Now I am trying to use custom properties instead of client tags! I tried to define a single column dataset inside the template repeater component to replicate the client tag array defined above. However these data sets are not mutable like arrays and not accessible from scripts outside the components like clients arrays are globally accessible.

Hope I get a solution with custom properties also soon.

That won't work, the i+1 part is just a string. I assume you wanted it like the line below.

path.append("[client]Hilight["+ str(tskNo) +"]")

Edit:
It's safer and easier to do this like so. Also, I'm not sure what the + are for

path.append( "[client]Hilight[%s]" % (i+1) )

Yes this was an edited code , didn't want to copy exact code, in the process some typo errors are left out. But you are right the actual code is a working one.

I tried the 1st part of your script, and the output seems fine

['[client]Hilight[0]', '[client]Hilight[1]', '[client]Hilight[2]', '[client]Hilight[3]', '[client]Hilight[4]', '[client]Hilight[5]', '[client]Hilight[6]', '[client]Hilight[7]', '[client]Hilight[8]', '[client]Hilight[9]', '[client]Hilight[10]', '[client]Hilight[11]', '[client]Hilight[12]', '[client]Hilight[13]', '[client]Hilight[14]', '[client]Hilight[15]', '[client]Hilight[16]', '[client]Hilight[17]', '[client]Hilight[18]', '[client]Hilight[19]', '[client]Hilight[20]']
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Try writing to the tags without the other fluff, just the writeBlocking with zeros. Are you sure the tag paths are correct?

This is basically initializing the client tag array to all zeros first , then appropriate indexes are initialized to 1 indicating to be hilighted templates in the repeater.