Change Script for use with "Shift change" custom property | Ignition Perspective

I have a change script that fires when shift change occurs and changes a session property property of "shiftChange" to "true" that looks at if the value goes from 1 to 2, 2 to 3, or 3 to 1. Otherwise we say that shiftChange is false. Shift is determined with a SQL query. My shift value is actively changing to new numbers at shift change like its supposed to but, however, at shift change, 1 to 2, 2 to 3, or 3 to 1, my shiftChange change script doesn't seem to work.

Why?

The idea is at shift change, I want to change the assigned user, assigned model number, assigned line, and repair station ids to empty and fire a pop-up to request the user to assign themselves to the "line". At shift change when my value changes from a number to a number, my changeScript on shiftChange doesn't fire.

Background:

Upon initial loading of the webpage, there's a startup script which checks for assigned values on the session property. If no values are assigned, a pop up window appears that requires the user to assign themselves to the line from a badge scan sql query, line drop down, model drop down, and repair location drop down. When I click save, the script writes to the session properties required (Line, Model, Repair Location, Auditor). The shift value is determined by the line selection value and a named query. At shift change, I want ignition to wipe out the assigned values in the session properties and require the user to reassign themselves to the line. However, something isn't working properly.

Any help would be awesome! I'm still new to this. I got my ignition perspective gold cert last month.

Shift value change script:

if previousValue != 1 and previousValue != 2 and previousValue != 3:
	self.custom.shiftChangeScript = False
else:
	self.custom.shiftChangeScript = True

shiftChangeScript change script:

if value is True: 
	self.custom.Auditor = ' '
	self.custom.Line = ' '
	self.custom.Location = ' '
	self.custom.BadgeNumber = ' '
	id = "lineconfigpopup"
	path = "Page/Quality Defect Entry POC/PopUps/LineAssignment"
	system.perspective.openPopup(id,path)

Is previousValue ever anything other than 1 or 2 or 3?
If not then this will always return False.

Yes. When the user initially sets up their interface, lets say the chromebox boots up (this is what I use to host the perspective page), the first thing it does is prompt the user to assign themselves. At this point, the shift value is nothing / ' '.

Also, I just tried this:

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
if previousValue is None or previousValue == '' and currentValue > 0:
self.custom.shiftChangeScript = False
if previousValue > 0 and currentValue > 0:
self.custom.shiftChangeScript = True
else:
self.custom.shiftChangeScript = False

Which seemed to work the first time but isn't firing right. I disabled binding on the shift session property and set the shift value to a 1, then to a 0, then back to a 2, but isn't doing what I originally thought it would. I thought that if the shift value is blank or 0, and then i change the shift value to a 1 that it would go back to "false" from "True" but that didn't pan out.

The only reason I did this was because I was afraid of the change script wiping the settings every time the user assigns themselves to the line from the beginning. I only want it to wipe the session values IF the shift number changes from 1 to 2, 2 to 3, or 3 to 1. Not any time the value changes.

If I am reading this correctly you want it to fire:

  • Upon application start
  • Specifically when shift changes from 1 to 2
  • Specifically when shift changes from 2 to 3
  • Specifically when shift changes from 3 to 1

Your script, as written, will only satisfy the fisrt condition.
I think this can be reduced to a single script, eliminating the need for the shiftChangeScript property.

if ((previousValue.value != 1 and previousValue.value != 2 and previousValue.value != 3) #application startup
     or (previousValue.value == 1 and currentValue.value == 2) # Start 2nd shift
     or (previousValue.value == 2 and currentValue.value == 3) # Start 3rd shift
     or (previousValue.value == 3 and currentValue.value == 1) # Start 1st shift
   ):
	self.custom.Auditor = ' '
	self.custom.Line = ' '
	self.custom.Location = ' '
	self.custom.BadgeNumber = ' '
	id = "lineconfigpopup"
	path = "Page/Quality Defect Entry POC/PopUps/LineAssignment"
	system.perspective.openPopup(id,path)

With that boiling down, isn't this basically just if previousValue != currentValue...which it won't, by definition, because this is a change script?

This whole script can probably just run literally whenever the property changes.

I agree, but he was very specific on the value changes.

1 Like

This is great feedback. I never thought about merging them together. I suppose, I was just over complicating it. I'm going to try your modified script to see if it works! It seems promising as I got an error stating that no perspective page was part of the thread (being in designer that makes sense?). I also had to remove all of the '.value' pieces of the script otherwise I was getting errors stating that there was no variable for 'value'. I will check back at shift change today!

Unfortunately, at shift change, nothing happened.

That doesn't narrow it down much.
Any error in the log?

I also recommend adding a logger. Somthing like this above the if statement:

logger = system.util.getLogger('ShiftChange')
logger.info('currentValue:{} previousValue:{}'.format(currentValue, previousValue)

should put an entry onto the log that you can use to help troubleshoot.

1 Like

So what I've done is set up some visible properties on one of the screens used to interact with the system. I've added a label that the script writes the current and previous values to as well as a status label to help me figure out what's wrong. It seems to be continuing to not make the statement true even though it is. I'm lost here. I've added a manual text entry field to change the shift value without waiting on actual shift change. It makes it to the end of the script to enter the values into the currentValue / previousValue labels I've generated as well as updates the status to the else statement, telling me that the if statement never becomes true when it should.

Attached is the modified change script as well as the fields I've added.

Post code, man! Post code - not pictures of code.

You don't have to delete posts. You can edit them (the pencil icon) to add styling (like "preformatted text" for code).

Thank you!

def valueChanged(self, previousValue, currentValue, origin, missedEvents):
	self.custom.status = ''
	from time import sleep
	sleep(2)
	if ((previousValue ==1 and currentValue ==2) # Start 2nd shift
    	or (previousValue == 2 and currentValue ==3) # Start 3rd shift
    	or (previousValue ==3 and currentValue ==1) # Start 1st shift
    	):
		self.custom.Auditor = ''
		self.custom.Line = ''
		self.custom.Location = ''
		self.custom.BadgeNumber = ''
		id = "lineconfigpopup"
		path = "Page/Quality Defect Entry POC/PopUps/LineAssignment"
		system.perspective.openPopup(id,path)
	else:
		self.custom.status = 'None of the statements are true'
	self.custom.currentValue = currentValue
	self.custom.previousValue = previousValue
	#((previousValue == 1 and currentValue == 2) or (previousValue == 2 and currentValue == 3) or (previousValue == 3 and currentValue == 1))
	

previousValue and currentValue are QualifiedValue objects. The real value in those are accessed with .value tacked on.

Ok, I will try that. I was getting errors in the designer with the '.value' at the end so I removed it. I appreciate you guys for being both patient and helpful!

That seemed to do the trick, in that it is clearing the values, now the pop-up isn't firing. Can I call a pop-up on a change script to a session property? (yes the pop-up does work, I use the same id and path on startup script for the defect entry screen)

I moved the change script to the defect entry page on a hidden helper label which is tied to the session property 'shift' and this worked. Thank you guys so much!

Are we happy with the sleep(2) line? It's generally a bad idea.

3 Likes

I removed it. No longer needed. Was only using it to figure out if it was firing things correctly. It looks more like the initial code posted by Jordan earlier.

1 Like