using duration in update scripts doesn't produce the correct values.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I have several locations where I am calculating a duration and then using that value later. When I calculate the value based on the difference in two date time fields, it shows up correctly and displays correctly. When I calculate based on what is showing in the duration field I get an entirely different value.
Same script, different results depending on where I get the source data from.
1st picture shows the table, with referenced table names.
2nd picture shows 1 result of running the script.
u_laborstart = date/time
u_laborend = date/time
u_laborduration = duration
Calculating the duration as u_laborend - u_laborstart works correctly.
Pulling the duration from what should be the same value gives an entirely different value. See code below.
What am I doing incorrectly when I pull the value from the duration field that results in such wacky values?
var durr = new GlideDuration(fd_data.trigger.current.u_laborduration);
var sec = durr.getByFormat('s');
var min = durr.getByFormat('m');
var hour = durr.getByFormat('h');
gs.info("travel duration was: " + hour +":" + min + ":" + sec);
var lst = new GlideDateTime(fd_data.trigger.current.u_laborstart);
var lnd = new GlideDateTime(fd_data.trigger.current.u_laborend);
//gs.info("lstart was " + lst.getNumericValue());
//gs.info("lend was " + lnd.getNumericValue());
var diff = lnd.getNumericValue() - lst.getNumericValue();
//gs.info("diff was " + diff);
var retVal = new GlideDuration(diff);
//fd_data.trigger.current.u_laborduration = retVal
//fd_data.trigger.current.update();
//gs.info("retval is " + retVal.getDisplayValue());
var hours = retVal.getByFormat('HH');
//gs.info("hours: " + hours);
var min = retVal.getByFormat('m');
//gs.info("minutes: " + min);
var secs = retVal.getByFormat('s');
//gs.info("seconds = " + secs);
gs.info("time spent was " + hours + ":" + min + ":" + secs)
var LaborCost = 25;
var totalCost = (hours * LaborCost) + (min/60 * LaborCost) + (secs/3600 * LaborCost)
fd_data.flow_var.cost = totalCost;
//fd_data.trigger.table_name.u_laborcost = totalCost;
//fd_data.trigger.table_name.u_totallinecost = totalCost;
//fd_data.trigger.table_name.update();
return retVal.getDisplayValue();
0 REPLIES 0