I have a template repeater with these components.
The Hours input is bound to a custom property on the template. The Start Time and End Time inputs have a propertyChange script that runs when the dataValue is changed, calculates the difference between the two, and writes it to the custom property that is bound to the Hours input.
This is the script on the Start Time and End Time inputs:
#If the time was changed, save the differennce between the two to the hour input if (event.propertyName == 'dateValue'): entryStart = event.source.parent.getComponent('entryStart').dateValue entryEnd = event.source.parent.getComponent('entryEnd').dateValue # Convert to milliseconds entryStartMS = system.date.toMillis(entryStart) entryEndMS = system.date.toMillis(entryEnd) # Time spent entryHoursMS = entryEndMS - entryStartMS # Convert to decimal hours. Make sur to use decimals (float), otherwise the resulting value will not have any. entryHours = entryHoursMS / (1000.0*60.0*60.0) # Save the value to the custom property. In turn, this will be saved to the input box event.source.parent.entryHours = entryHours
This script works great. In the screenshot, because start = end, hours = 0.
The problem is that when this template is originally loaded, I don’t want this script to run. I am using a template repeater. Usually the custom property of the template has a value and I want that to be displayed in the input box until a user changes either the Start Time or End Time. The Start Time and End Time properties are not always used or saved, so I can not rely on my script to calculate the hours every time.
So… Can anyone give me an idea how I can do this? I would like the Hours input to use the custom property value, until a user changes either the start or end time where it will then use the value calculated by the script- and not before.
Alternatively, if someone knows a better way to do this, I’m all ears!