How to get the time in along with the date in glide duration in the business rule.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2023 10:30 PM
Hi,
There is a business rule written on "sn_vul_vulnerable_item" table to calculate the business days. Below is the script for the same.
It is an onBefore business rule. Currently it is calculating the target date only based on the field "last_opened_dt_tm". My requirement is to calculate the time also along with the date. How can I do that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 02:25 AM
I have used the below script as well, but not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 02:30 AM
small update in the script I shared earlier.
(function executeRule(current, previous /*null when async*/ ) {
//Fetching last Opened Date
var lastOpenedDate = new GlideDateTime(current.last_opened_dt_tm);
//Adding business days
var date = new GlideDateTime();
var days = parseInt(current.ttr_applied_rule.ttr_max);
var dur = new GlideDuration((60 * 60 * 8 * 1000 * days));
var schedule = new GlideSchedule('82fba44e877e655098264b59dabb35dd');
var newDateTime = schedule.add(date, dur);
//Updating new target date
current.ttr_target_date = newDateTime;
})(current, previous);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 02:40 AM
Tried that, didn't calculated date.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 03:14 AM
what's your schedule? how many hours are there in it?
Did you manually check what time you get by adding those days to the start date?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2023 03:29 AM
Below is the schedule:
The date is calculated correctly based on the field "last_opened_dt_tm", but it is not calculating the time. Some time the time is taken as '2023-06-01 17:00:00' for last opened date "2023-05-19 00:00:00"and '2023-05-29 00:00:00' for last opened date "2023-05-19 00:00:00" as shown in above attachment.