Hello all,
I am currently struggling with a portion of my script concerning currentValue.value and previousValue.value on a property change script. I will include my script below before going into detail on my issue:
def valueChanged(self, previousValue, currentValue, origin, missedEvents):
#Variables
FirstName = self.props.selection.data[0].FirstName
LastName = self.props.selection.data[0].LastName
PreviousYearlyOvertime = self.props.selection.data[0].PreviousYearlyOvertime
WeeklyOvertime = self.props.selection.data[0].WeeklyOvertime
SaturdayOvertime = self.props.selection.data[0].SaturdayOvertime
SaturdayRejected = self.props.selection.data[0].SaturdayRejected
SundayOvertime = self.props.selection.data[0].SundayOvertime
SundayRejected = self.props.selection.data[0].SundayRejected
HolidayOvertime = self.props.selection.data[0].HolidayOvertime
SaturdayHours = self.props.selection.data[0].SatHrs
SundayHours = self.props.selection.data[0].SunHrs
TotalWeekOvertime = float(WeeklyOvertime) + float(SaturdayOvertime) + float(SaturdayRejected) + float(SundayOvertime) + float(SundayRejected) + float(HolidayOvertime)
TotalYearlyOvertime = float(TotalWeekOvertime) + float(PreviousYearlyOvertime)
OvertimeWeek = self.getSibling("Table Date").props.text
Today = system.date.now()
Time = system.date.format(Today, "MM/dd/YYYY hh:mm:ss a")
Date = system.date.format(Today, "MM/dd/YYYY")
userID = self.session.props.auth.user.userName
Type = "Edited"
LogEntry = userID + " edited " + LastName + ", " + FirstName + " Weekly overtime to " + str(WeeklyOvertime) + " for the date of " + str(Date) + "."
params = {"FirstName" :FirstName, "LastName" :LastName, "OvertimeWeek" :OvertimeWeek, "WeeklyOvertime" :WeeklyOvertime}
params2 = {"FirstName" :FirstName, "LastName" :LastName, "OvertimeWeek" :OvertimeWeek, "TotalWeekOvertime" :TotalWeekOvertime, "TotalYearlyOvertime" :TotalYearlyOvertime}
params4 = {"FirstName" :FirstName, "LastName" :LastName, "TotalYearlyOvertime" :TotalYearlyOvertime}
logParams = {"Time" :Time, "LogEntry" :LogEntry, "Type" :Type}
#Runs query to update database table
system.db.runNamedQuery("Overtime/Charge Hours/Weekly Overtime Update", params)
#Runs query to update week and YTD totals
system.db.runNamedQuery("Overtime/Charge Hours/Total Week And Year", params2)
#Runs query to return new table
returnedData = system.dataset.toPyDataSet(system.db.runNamedQuery("Overtime/Charge Hours/Mechanics Pull", {"OvertimeWeek" :OvertimeWeek}))
NewValue = sorted(
dict(zip(returnedData.columnNames, list(row)))
for row in returnedData,
key = lambda columns: (columns['LastName'], columns['FirstName']))
self.props.data = NewValue
#Variables for query
Change = float(currentValue.value) - float(previousValue.value)
system.tag.writeBlocking("[default]MOS/Mechanic Weekly", Change)
Changed = system.tag.readBlocking("[default]MOS/Mechanic Weekly Change")[0].value
NewSaturdayHours = float(SaturdayHours) + Changed
params3 = {"FirstName" :FirstName, "LastName" :LastName, "NewSaturdayHours" :NewSaturdayHours}
#Runs query to update SatHrs on MOS_Employee table
system.db.runNamedQuery("Overtime/Charge Hours/Saturday Hours Update", params3)
#Runs query to update MOS_Signup
system.db.runNamedQuery("Overtime/Charge Hours/Signup Update", params4)
#Runs query to add to log
system.db.runNamedQuery("Configuration/Logs/Log Entry", logParams)
I have this script on valueChanged on my table within selection.data.0.WeeklyOvertime. When the value changes, it runs several queries. First, it runs Weekly Overtime Update, this query sets the new weekly overtime value to the table. Next, it runs Total Week and Year, this query sets the new totals for the week and YTD. The fourth query updates another table with the YTD, and the fifth query inserts a changes into a log. The third query is the query I am really struggling with to get functioning quite the way I want. I have the variable Change equal to the total from currentValue.value - previousValue.value. Because of the table refresh, it sets the value back to 0. I have it write to a tag to try and hold this value, though it seems very inconsistent. Every time on the first click it also runs the query. I've tried things like "if currentValue.value != WeeklyOvertime, then click a cell and it still runs when I don't want it to. I'm trying to find the change so that I can subtract or add it to a column on another table to show the updated value, whether it be a few more or a few less hours. Does anyone have any advice on a better way to complete this task?