PropertyChange Script Running on load

I’ve read a bunch of the forum posts about trying to stop the propertyChange script from running when it shouldn’t and I can’t get my script to cooperate the way I’d like.

I am loading a template repeater full of writable floats that will prompt the user before committing a change to the underlying tag. The problem is the prompt constantly popping up on the initial load thinking a value has been changed and should be written down to the tag.

I have a Numeric text field with the FloatValue filled in from a setpoint tag (uni-directionally). The text field has a custom property (“RawData”) which is bound to the Numeric Text Field.FloatValue (Uni-Directionally) When the operator makes a change the script runs and verifies that the floatValue != rawData. But this causes the propertyChange script to not run.

if event.propertyName == "floatValue" and event.source.floatValue != event.source.rawData:
		if system.gui.confirm("Are you sure you want to change the setpoint to: " + str(event.newValue),"Change Confirmation."):
			system.tag.write (event.source.parent.RootFolder+"/Setpoints/"+event.source.parent.SetpointName+"_LO_SP",event.newValue)

Try adding

if event.propertyName != 'componentRunning': 

I have done that, my script only runs when the propertyName == “floatValue” too so wouldn’t that already take care of that?

I may have spoken to soon here is the code that fixed my issues and so far seems to be working as I needed.

if event.propertyName!= 'componentRunning':
	newPath =  event.source.parent.RootFolder+"/Setpoints/"+event.source.parent.SetpointName+"_LO_SP"

	if event.propertyName == "floatValue" and event.newValue!= system.tag.read(newPath).value:
			if system.gui.confirm("Are you sure you want to change the setpoint to: " + str(event.newValue),"Change Confirmation."):
				system.tag.write (newPath,event.newValue)
			else:
				event.source.floatValue = event.oldValue	
1 Like

Scratch that, it looked like it was working perfectly in the designer but as soon as I put it on the run-time I had an infinite amount of pop-up windows bog down the system.

I’m not sure on this, I don’t use the template repeater much. I did create my own template with a numeric text field with a tag binding then added a if event.propertyName == 'floatValue': I made a template repeater with the template and when the page loaded it didn’t trigger anything upon opening. but I did not try it in a client, just the designer. Maybe you need to restrict it some how with the componentRunning property on the template itself, not the text fields?? Of course your floatValue checking to the rawData should take care of that. I’m really not sure how it is getting to the confirmation popup code.

You should not have a propertyChange script that checks that the event is for a propertyName not equal to a given name. That script section will run for all of the little things that change that you don’t care about, blowing up your CPU.

1 Like

OK, I’ve updated my script to do what you suggested somewhere else.

I tie a custom property to the tag i want then I tie the text entry field floatValue to the custom property. the rest of my script looks like this and it still causing unwanted pop-ups:

if event.propertyName == "floatValue" and event.newValue != event.source.rawData:
	newPath =  event.source.parent.RootFolder+"/Setpoints/"+event.source.parent.SetpointName+"_LO_SP"
	
	if system.gui.confirm("Are you sure you want to change the setpoint to: " + str(event.newValue),"Change Confirmation."):
		system.tag.write (newPath,event.newValue)
		event.source.rawData = event.newValue

Don’t use a confirm or any other message popup within a propertyChange – those events must complete immediately. Your code will only prevent multiple popups if the assignment to rawData is unconditionaly.

Thanks for all the input! I got this to work the way I needed to by re-visitiing some of pturmels other posts on the topic. I wasn’t worried about using the pop-ups in the propertyChange script because they will only be displayed if a user has modified the floatValue field.

My numeric text entry is set up as follows:

  • A custom property rawData of type float was added to the tag
  • rawData was uni-directionally bound to a setpoint tag
  • the Numeric Text Entry - floatValue was then bound to the rawData custom property.

After that my propertyChange script became:

if event.propertyName == "floatValue" and event.newValue != event.source.rawData and event.source.rawData!= event.source.floatValue:
	newPath =  event.source.parent.RootFolder+"/Setpoints/"+event.source.parent.SetpointName+"_LO_SP"
	
	if system.gui.confirm("Are you sure you want to change the setpoint to: " + str(event.newValue),"Change Confirmation."):
		system.tag.write (newPath,event.newValue)
		event.source.rawData = event.newValue
	else:
		event.source.floatValue = event.source.rawData
1 Like