GlideDateTime.subtract doesn't work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2017 05:58 PM
I used the following commands on default value to calculate the number of days subtracting current date to due date but didn't work. Any comment or advise is greatly appreciated.
javascript:calendar_duration = GlideDateTime.subtract(due_date.getDisplayValue(), gs.nowDateTime());
Following this syntax:
<duration_field> = GlideDateTime.subtract(<start_field>.getDisplayValue(),gs.nowDateTime());
- Labels:
-
Personal Developer Instance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 06:55 PM
Hi Rouf
Check the below thread where user was successfully able to use the calculated field option. This may be helpful.
How to set Calculated Value for Duration (or any other date/time) field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 10:48 AM
have you verified that it's running? do you have a business rule queuing the event problem.updated?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 11:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2017 07:07 PM
Mohammed
Please try this script, you need to make your duration field(your required field) a calculated value
Script:
(function calculatedFieldValue(current) {
var startDate = new GlideDateTime(current.due_date); // your required feild
//var endDate = new GlideDateTime(current.closed_at);
var today = new GlideDateTime();
var result = GlideDateTime.subtract(startDate, today);
return result;
Note: I believe you have a due date and you want to make your "duration" field a calculated value??
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
‎12-11-2017 10:06 PM
No luck. I used this. I changed the field name with type Date for both.
(function calculatedFieldValue(current) {
var startDate = new GlideDate(current.u_rcaduedate); // your required feild
//var endDate = new GlideDateTime(current.closed_at);
var today = new GlideDate();
var result = GlideDateTime.subtract(startDate, today);
return result;
})(current);
Getting this errors from "Script-Background"
Evaluator: org.mozilla.javascript.EcmaError: Cannot read property "u_rcaduedate" from null Caused by error in script at line 2 1: (function calculatedFieldValue(current) { ==> 2: var startDate = new GlideDate(current.u_rcaduedate);