Skip to content

Commit e3a5bcd

Browse files
authored
Milliseconds duration (#1439)
* Create millisecondsToDuration.js * Create readme.md * Create Milliseconds to Duration * Delete readme.md * Delete millisecondsToDuration.js * Create readme.md * Create millisecondsToDuration.js * Delete Milliseconds to Duration directory * Delete Flow Actions/Milliseconds to Duration * Create readme.md * Create millisecondsToDuration.js * Update readme.md
1 parent b6383f7 commit e3a5bcd

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(function execute(inputs, outputs) {
2+
3+
var gdt0 = new GlideDateTime("1970-01-01 00:00:00"); //Epoch DateTime
4+
var gdt1 = inputs.milliseconds;
5+
gdt0.add(gdt1); // Adds the milliseconds to the epoch date/time
6+
7+
outputs.time = gdt0.toString();
8+
9+
})(inputs, outputs);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
When you use flow designer to calcualte the difference between two duration fields, these duration fields need to be changed into milliseconds using dateNumericValue(). This can be done in a flow variable similar to the example below:
2+
3+
var timeWorked = fd_data.trigger.current.u_total_time_worked;
4+
timeWorked = timeWorked.dateNumericValue();
5+
6+
var estimatedTime = fd_data.trigger.current.change.u_impact_assessment.u_change_request_effort_total;
7+
estimatedTime = estimatedTime.dateNumericValue()
8+
9+
var remainingTime = estimatedTime - timeWorked;
10+
11+
return remainingTime;
12+
13+
To be able to convert the millisections back into a duration fields, this flow designer action uses:
14+
15+
- the milliseconds (reaminingTime) from the calculation as the input in an integer value
16+
- the the code will add the milliseconds to the ServiceNow Epoch DateTime which the duration fields uses and then returns the time difference back into a string that can be added to a duration field
17+
- the output of the action needs to be set to the time as a duration type field

0 commit comments

Comments
 (0)