I have a scenario in which I am building a perspective page that does not use any tags. A user will scan a barcode or manually enter it, triggering a few events such as fetching drawing data from our drawing web service and collecting product information from our ERP system via a web service. All of these actions are initiated from an on-change script on an order number field.
Everything is working as intended, except for one aspect. The team leads would like the screen to change even if the same order number is scanned. Due to everything being in a change script, nothing happens when the same value is entered. Therefore, I am attempting to design the system so that if the same number is scanned, the following actions occur:
- Clear the order number value (which triggers the change script, setting values to blank).
- Wait for 3 seconds.
- Re-enter the order number(triggering the on-change script to execute all the necessary events for pulling drawings and product information.)
I have something working using a time.sleep
, but I know that this is not the correct way to achieve this. What would be a suitable solution for implementing a timer that clears the values, waits for 3 seconds, and then re-enters the order number?
My current solution involves order_number_prep
, which writes directly to my order_number
. If the values don't match, it writes to the order_number
. If they do match, it clears the field for 3 seconds and then writes the number back.
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
import time
if len(str(currentValue.value)) > 0:
if str(currentValue.value) != str(self.custom.order_number):
self.custom.order_number = currentValue.value
self.custom.order_number_prep = ''
else:
self.custom.order_number = ''
time.sleep(3)
self.custom.order_number = currentValue.value
self.custom.order_number_prep = ''