How to use propConfig in script way

I’d like to bind different actions for different components in a flex repeater on value change of that component , action content is from a field of DB table , everything is working well if I manually set by [add change script] when I right click property , my problem is I have to dynamically bind them by setting propConfig due to too many components .

Any ideas would be appreciated.

Any ideas?

Python functions are first-class objects, and can be dynamically picked out of a script module with the getattr() built-in function. Create a script module with a function for each allowed action. Place the function name in a column of your DB table of component definitions.

Could you please add more details?
My on view start up event script is :

	params = {"stationFullCode": self.view.params.stationFullCode}
	system.perspective.print ("stationFullCode222222")
	dtTags = system.db.runNamedQuery("SandboxTest", "IgnitionDB/GetTagsByStationFullName",  params)
	
	pyDataTags = system.dataset.toPyDataSet(dtTags)
	system.perspective.print(pyDataTags)
#	system.perspective.print(self.scripts)

	rptTags = self
	instances =[]
	propConfig ={}#rptTags.propConfig
	i=0
	for tag in pyDataTags:
		id = tag["Id"]
		opcPath = tag["OpcPath"]		
		tagName = tag["TagName"]
		opcUaServerName = tag["OpcUaServerName"]
		tagText = tag["TagText"]		
		onValueChangeScript = tag["OnValueChangeScript"]
		onQualityChangeScript = tag["OnQualityChangeScript"]
		instance ={
		          "instancePosition": {},
		          "instanceStyle": {
		            "classes": ""
		          },
		          "text": tagText,
		          "value": 1,
		          "tagFullPath":"[default]DynamicTags/TestDynamicPlc"
		        }
		instances.append(instance)
		tagValueBinding = {
		        "binding": {
		          "config": {
		            "fallbackDelay": 2.5,
		            "mode": "direct",
		            "tagPath": "[default]DynamicTags/TestDynamicPlc"
		          },
		          "type": "tag"
		        },
		        "onChange": {
#		          "enabled": null,
		          "script": "\tsystem.perspective.print( previousValue)\n"
		        }
		      }
		tagValueFullName =  "props.instances[%s].tagValue"%(i)
		propConfig[tagValueFullName] = tagValueBinding
	rptTags.props.instances = instances	
	rptTags.propConfig = propConfig

Works:
p = getattr(self, "props")
Doesn't work
p = getattr(self, "propConfig")

I can see propConfig is out there, just can not get and set, logs: AttributeError: 'com.inductiveautomation.perspective.gateway.script' object has no attribute 'propConfig'

    "position": {
      "grow": 1,
      "basis": "100px"
    },
    "custom": {},
    "propConfig": {
      "props.instances[0].tagFullPath": {
        "onChange": {
          "enabled": null,
          "script": "\t2222222"
        }
      },
      "props.path": {
        "onChange": {
          "enabled": null,
          "script": "\t"
        }
      }
    },

I am gonna say I do not recommend to do so, I resolved with exec

	s ="system.perspective.print (\"From string  stationFullCode222222\")\nsystem.perspective.print (\"From string  stationFullCode33332\")\nsystem.perspective.print (\"From string  stationFullCode444422\")"
	exec(s)

I’m not recommending you try to dynamically change the config, but include code in the one config that looks up the correct function to run.

You simply cannot dynamically create bindings at runtime. It’s something a few ‘power users’ have asked for, but we don’t have any concrete plans to implement such a thing at the moment. If you just want to quickly create many views, you could theoretically try to create a well-formed JSON structure and write it to the filesystem - but I’d advise against such a thing.

1 Like

@PGriffith
Hmm, I understand potential dead loop risk and that’s gonna be headache in the future, all I wanna do is:

  1. Create tags dynamically by clicking save button
  2. Execute dynamical actions when tag value changes
    a. Save data to db
    b. Update table on view

Which do you think is the best way to implement this feature?

Some project done for me and I’ve never need such a thing like dynamic binding.

Do you create tags dynamically?

yeah, use system.tag.configure - Ignition User Manual 8.1 - Ignition Documentation (inductiveautomation.com) to do so.
And for binding you may use com.inductiveautomation.ignition.common.sqltags.model.TagProp, but I haven’t used it yet.

What do you do if tag value changes? In my case , I wanna do following steps:

Build info and store into DB or Update certain fields maybe also.
My case is :
1. Build info by Scanning bar code
2. Update a field after a few minutes with another bar code from another PLC
Update UI intermediately( This feature I could implement by fetching data very often )

Adding a script in value change field?
Using multiple tags…
Use another tag like a watch dog to perform a trigger to update the UI
I don’t know, there will always be another path to take in my opinion.
You can even use JSON or XLM to build, store and retrieve tags as well