I've been combing through the forums, Pubs and Manuals to create this code and cannot seem to get it to give me my answer.
I mean it doesn't display the result in my "StopTime" Text-field (Time - h:MM tt) and because I cannot figure out how to view my results line by line.
I don't know if it's because of prior code.
Could someone please advise what I'm doing wrong.
Here is the code I've created;
// get the start time and added time
var sStart = this.getField('StartTime').value;
var sWork = this.getField('Work').value;
var sTravel = this.getField('Travel').value;
//Convert Time to seconds
var vStart = Time2Num(sStart.FormattedValue, "h:MM tt");
var vWork = (sWork * 3600000);
var vTravel = (sTravel * 3600000);
If(HasValue('Work') & HasValue('Travel'))
// Add Time
var vTotal = vStart + vWork + vTravel;
// Add Time
var vTotal = vStart + vWork;
// Add Time
var vTotal = vStart + vTravel;
// Convert to time
var vStop = Num2Time(vTotal, "HH:MM");
// Display Time
event.value = ''
'StopTime'.value = util.printd("h:MM tt", vStop);
Any help would be greatly appreciated.
If you copy and paste code from other scripts you have to make sure you copy all of the relevant parts. All of the functions you're using in your code (HasValue, Time2Num, Num2Time, etc.) are not defined in your code, so it can't work.
Thanks for your reply, I typed them in straight up.
So do I need to import something into my form for these functions to work like a macro of some kind.
Thanks for the quick reply,
You need to find the definitions of those functions and include them in your code, yes.
Why can't they make one common set of source commands for all their line of products.
Hope this Newbie is up to it, thanks for your direction.
I think all of this code comes from an LCD document, which is not the same as a regular PDF file, so you can't use it.
What is it exactly that you're trying to calculate?
I need to take the accumulated hours worked / traveled and add them to the start time of the service team member.
The resulting value being the finish time.
Adding a little error proofing of the daily log sheets.
Everything I found revolves around the date not the time.
Creation of a Function is a good idea for future edits and/or forms.
If you have a good starting place I'm all ears.
These tutorials are a good starting point:
Also, if you're interested, I've developed a (paid-for) tool that allows you to set up such calculations very easily:
Seen all of these and they are all time difference between, known times.
I'm trying to create the second time.
I'll use them as a base to develop the reverse of Thom Parker work.
Read quite a bit of his stuff looking for what I need.
Thank you for the insight.
I could still develop it for you, if you wish. Contact me privately to discuss it further, please.
Found the answer,
Ended up being simpler then I thought, I didn't need to destruct the time strings.
Add the results and convert back using Functions.
Anyone that needs to add worked hours to a start time here is what I found and did.
And it's good for 24hr logging.
// Get field values as numbers and calculate sum
var vServiceRow1 = +getField("ServiceRow1").value;
var vServiceRow2 = +getField("ServiceRow2").value;
var vServiceRow3 = +getField("ServiceRow3").value;
var vServiceRow4 = +getField("ServiceRow4").value;
var vServiceRowSum = vServiceRow1 + vServiceRow2 + vServiceRow3 + vServiceRow4;
var vWarrantyRow1 = +getField("WarrantyRow1").value;
var vWarrantyRow2 = +getField("WarrantyRow2").value;
var vWarrantyRow3 = +getField("WarrantyRow3").value;
var vWarrantyRow4 = +getField("WarrantyRow4").value;
var vWarrantyRowSum = vWarrantyRow1 + vWarrantyRow2 + vWarrantyRow3 + vWarrantyRow4;
var vIdleRow1 = +getField("IdleRow1").value;
var vIdleRow2 = +getField("IdleRow2").value;
var vIdleRow3 = +getField("IdleRow3").value;
var vIdleRow4 = +getField("IdleRow4").value;
var vIdleRowSum = vIdleRow1 + vIdleRow2 + vIdleRow3 + vIdleRow4;
var vBreak = +getField("Break").value;
event.value = vServiceRowSum + vWarrantyRowSum + vIdleRowSum + vBreak;
if (event.value == 0)
event.value = "";
event.value = "";
var vStartTime = this.getField("StartTime").valueAsString;
var d = util.scand("mm/dd/yyyy HH:MM", "01/01/2017 " + vStartTime);
var v = this.getField("Work").valueAsString;
var addTimeHours = Number(v);
var msPerHour = 3600000;
d.setTime(d.getTime() + (addTimeHours * msPerHour));
event.value = util.printd("HH:MM", d);