Setting duration fields using Flow Designer is not working.

John Prouty
Kilo Guru

I have three duration fields in my table.  However, they do not render the some. 

find_real_file.png

"Remaining Elapsed Time" displays Days, Hours, Minutes and Seconds.

"Duration to Step" and "Step Duration" are a single fields.

here is the table definition:

find_real_file.png

I don't see any difference in the specification of the three fields.

I am trying to calculate "Duration to Step" and "Step Duration" in the Flow Designer.  I built this custom Action to do so:

find_real_file.png

When I test my Flow, you can see that it is calculating the duration properly (note Run Start Time is GMT, Started is PST.  When Run Start Time is adjusted to PST, the difference is 13 minutes):

find_real_file.png

So the Action is working correctly.  However, the update is not.

Here is the details of the updates the Update Record is performing:

find_real_file.png

When I click on the Runtime value link to show the actual record, I get:

find_real_file.png

Step Duration is still blank and still a single field.  It should be 0 Days, 0 hours, 13 minutes, 6 seconds.

Why isn't it updating and why is the duration field being displayed as a single field and not like "Remaining Elapsed Time"?

1 ACCEPTED SOLUTION

John Prouty
Kilo Guru

Here is the working Action:

(function execute(inputs, outputs) {

     var starting_date = new GlideDateTime(inputs.start_date);
     var ending_date = new GlideDateTime(inputs.end_date);
     var time_zone_adj = new GlideTime();
     time_zone_adj.setValue("08:00:00");
     starting_date.add(time_zone_adj);
     ending_date.add(time_zone_adj);

     var schedule = new GlideSchedule(inputs.schedule_sys_id);
     var duration = schedule.duration(starting_date, ending_date);
     //outputs.message = "Duration: " + duration.getDurationValue();

     outputs.starting_date = starting_date;
     outputs.ending_date = ending_date;
     outputs.duration = duration;

})(inputs, outputs);

View solution in original post

4 REPLIES 4

Jon23
Mega Sage

Hi @John Prouty,

I believe your duration field is displaying as a single field because it is set to read only on the dictionary record, where as the 'Remaining Elapsed Time' field is read only using a UI policy.

John Prouty
Kilo Guru

I fixed the formatting issue, but the fields are still all 0's.  Any ideas on how to fix that?

Using the following code i was able to successfully update a duration type field.  You should be able to use it as a template to get your script functioning:

(function execute(inputs, outputs) {

var gdt0 = new GlideDateTime("1970-01-01 00:00:00"); //Epoch DateTime
var gdt1 = new GlideDateTime(inputs.createdDT);
var gdt2 = new GlideDateTime(inputs.updatedDT);
var durTime = GlideDateTime.subtract(gdt1, gdt2);
var ms = durTime.getNumericValue(); //convert the duration time to millieseconds
gdt0.add(ms); // Adds the milliseconds to the epoch date/time

outputs.durationt = gdt0.toString(); 
 
})(inputs, outputs);

John Prouty
Kilo Guru

Here is the working Action:

(function execute(inputs, outputs) {

     var starting_date = new GlideDateTime(inputs.start_date);
     var ending_date = new GlideDateTime(inputs.end_date);
     var time_zone_adj = new GlideTime();
     time_zone_adj.setValue("08:00:00");
     starting_date.add(time_zone_adj);
     ending_date.add(time_zone_adj);

     var schedule = new GlideSchedule(inputs.schedule_sys_id);
     var duration = schedule.duration(starting_date, ending_date);
     //outputs.message = "Duration: " + duration.getDurationValue();

     outputs.starting_date = starting_date;
     outputs.ending_date = ending_date;
     outputs.duration = duration;

})(inputs, outputs);