Calculating Duration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2017 11:09 PM
I am trying to calculate the duration of stay on a table called reservation. I have arrival and departure fields on it. I wrote a before business rule
var a = new GlideDateTime("current.arrival.getDisplayValue()");
var b = new GlideDateTime("current.departure.getDisplayValue()");
var c =GlideDateTime.subtract(a,b);
var gr = new GlideRecord('x_53167_hotel1_reservation');
// the code works fine till here.
gr.setDisplayValue('duration',c); // this line doesn't work fine.
gr.update();
I get the error that - Function setDisplayValue is not allowed in scope x_53167_hotel1
I tried changing to gr.reservation.setDisplayValue('duration',c) and then I get the following error:
org.mozilla.javascript.EcmaError: The undefined value has no properties.
Caused by error in sys_script.0fe98c150f444300890ecf8ce1050e9e.script at line 9
6: var c =GlideDateTime.subtract(a,b);
7:
8: var gr = new GlideRecord('x_53167_hotel1_reservation');
==> 9: gr.reservation.setDisplayValue('duration',c);
10: gr.update();
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2017 12:11 AM
We calculate incident duration on our incident form using the below script in a before insert and update business rule that runs when the u_incident_fix field is changed.
current.u_incident_downtime= gs.dateDiff(current.opened_at.getDisplayValue(),current.u_incident_fix_time.getDisplayValue(),false);
i suppose for you it would be:
current.u_stay_duration=gs.dateDiff(current.arrival.getDisplayValue(),current.departure.getDisplayValue(),false);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2017 04:21 PM
What is the data type of opened_at, fix_time and incident_downtime ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-10-2017 12:42 AM
The opened_at and u_incident_fix_time fields are date/time, u_incident_downtime is a duration field.