- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2019 06:58 AM
I have a two fields on my table which are of date/time type; I have start date and end date, inorder to calculate the difference i have created a new field of type duration
Business rule is been for this it returns a value in "days:hours:minutes"seconds"
Instead i just want the field to calculate the value in minutes; can someone please help me with this
Business rule:
(function executeRule(current, previous /*null when async*/) {
if (current.u_incident_start_date.nil() || current.u_incident_end.nil()) {
current.setValue('u_incident_duration_calculation', '');
return;
}
var st = new GlideDateTime();
st.setValue(current.getValue("u_incident_start_date"));
var ed = new GlideDateTime();
ed.setValue(current.getValue("u_incident_end"));
var dur = GlideDateTime.subtract(st, ed);
current.setValue("u_incident_duration_calculation", dur.getValue());
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Notifications
-
Workflow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2019 11:17 AM
That could be the issue. If you donot want decimals , try the updated code
(function executeRule(current, previous /*null when async*/) {
if (current.u_incident_start_date.nil() || current.u_incident_end.nil()) {
current.setValue('u_incident_duration_calculation', '');
return;
}
var st = new GlideDateTime(current.u_incident_start_date);
var ed = new GlideDateTime(current.u_incident_end);
var sec = gs.dateDiff(st, ed, true);
var minutes = sec/60;
current.u_incident_duration_calculation = parseInt(minutes,10); // Remove decimals
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2019 11:17 AM
That could be the issue. If you donot want decimals , try the updated code
(function executeRule(current, previous /*null when async*/) {
if (current.u_incident_start_date.nil() || current.u_incident_end.nil()) {
current.setValue('u_incident_duration_calculation', '');
return;
}
var st = new GlideDateTime(current.u_incident_start_date);
var ed = new GlideDateTime(current.u_incident_end);
var sec = gs.dateDiff(st, ed, true);
var minutes = sec/60;
current.u_incident_duration_calculation = parseInt(minutes,10); // Remove decimals
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2019 09:11 PM
Thank you so much for your help..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2019 08:23 AM
Can you try something like this.
var gd = gs.dateDiff(gr.getDisplayValue('u_incident_end'), gr.getDisplayValue('u_incident_start_date'), true); // gd will in seconds
var min = gd/1440; //Do you calculation,
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2019 10:05 AM
Hi Prateek,
I did something like this but it displays some wrong calculations, can you please help with above script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2019 10:12 AM
is u_incident_end and u_incident_start_date are date fields???
Please mark my response as correct and helpful if it helped solved your question.
-Thanks