- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2017 01:04 PM
Hi,
I am unsuccessfully trying to dynamically set/calculate 'duration' field value based on difference between opened_at and closed_at fields in an scoped application.
I tried using script below for 'calculated value' but no luck.
Thanks in advance.
(function calculatedFieldValue(current) {
var startDate = current.opened_at;
var endDate = current.closed_at;
var duration = GlideDateTime.subtract(startDate, endDate);
return duration;
})(current);
I tried also:
return GlideDateTime.substract(opened_at,closed_at);
but no luck - -my calculated field show <empty> value.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2017 09:29 AM
Can we try something like this
(function calculatedFieldValue(current) {
var startDate = new GlideDateTime(current.opened_at);
var endDate = new GlideDateTime(current.closed_at);
var duration = GlideDateTime.subtract(startDate, endDate);
return duration.getDisplayValue();
})(current);
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 08:57 PM
I updated the script removing time like GlideDate but same errors.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2018 06:23 AM
Hello Prateek,
Can you please help me with this
https://community.servicenow.com/community?id=community_question&sys_id=bf8b249cdb4f9b04e0e80b55ca9619c6

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2020 11:44 AM
This works with two date fields, but we want to calculate the number of days before go live.
Go Live date - Today's date
The below script is not working. Please assist
(function calculatedFieldValue(current) {
var gdt = new GlideDateTime();
var goLive = new GlideDateTime(current.u_golive_date.getDisplayValue());
var duration = GlideDateTime.subtract(goLive,gdt);
return duration;
// return the calculated value
})(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2020 06:17 PM
Try below:
(function calculatedFieldValue(current) {
var gdt = new GlideDateTime();
var goLive = new GlideDateTime(current.u_golive_date);
var duration = GlideDateTime.subtract(goLive,gdt);
return duration.getDisplayValue();
// return the calculated value
})(current);
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
06-24-2020 08:04 PM